RedHat修改源、主机名、静态IP、及克隆后网卡非eth0问题

    • 修改源
    • 修改主机名
    • 配置静态IP
    • 克隆后网卡非eth0

修改源

为Redhat6修改源

mv /etc/yum.repos.d/rhel-source.repo /etc/yum.repos.d/rhel-source.repo.bak
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo ~/
cp ~/CentOS6-Base-163.repo /etc/yum.repos.d/rhel-source.repo

sed -i "s/\$releasever/6/g" /etc/yum.repos.d/rhel-source.repo

yum clean all
yum makecache -y
yum update -y

修改主机名

主机名

[root@localhost ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain

修改/etc/sysconfig/network

MYHOSTNAME=redhat-pca
sed -i "s/\(HOSTNAME=\).*$/\1$MYHOSTNAME/g" /etc/sysconfig/network
[root@localhost ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=redhat-pca
[root@localhost ~]#

修改/etc/hosts

sed -i "/127.0.0.1/s/$/\t$MYHOSTNAME/g" /etc/hosts
sed -i "/::1/s/$/\t$MYHOSTNAME/g" /etc/hosts
[root@localhost ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4    redhat-pca
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6    redhat-pca
[root@localhost ~]#

配置静态IP

网络:

当前配置

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="dhcp"
HWADDR="00:0C:29:20:DA:65"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="8e096231-fe7f-46dd-b20e-a6609d8d33b1"
[root@localhost ~]#

设置静态IP

IPADDR=192.168.11.150
NETMASK=255.255.255.0
GATEWAY=192.168.11.2
DNS=192.168.11.2

sed -i "s/\(BOOTPROTO=\).*$/\1\"static\"/g" /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i "s/\(ONBOOT=\).*$/\1\"yes\"/g" /etc/sysconfig/network-scripts/ifcfg-eth0
# 如果还没有配置IP
echo -e "DNS1=$DNS\nIPADDR=$IPADDR\nNETMASK=$NETMASK\nGATEWAY=$GATEWAY\n" | tee -a  /etc/sysconfig/network-scripts/ifcfg-eth0
# 如果已经配置过
sed -i "s/\(DNS1=\).*$/\1$DNS/g" /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i "s/\(IPADDR=\).*$/\1$IPADDR/g" /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i "s/\(NETMASK=\).*$/\1$NETMASK/g" /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i "s/\(GATEWAY=\).*$/\1$GATEWAY/g" /etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="static"
HWADDR="00:0C:29:20:DA:65"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="8e096231-fe7f-46dd-b20e-a6609d8d33b1"
DNS1=192.168.11.2
IPADDR=192.168.11.150
NETMASK=255.255.255.0
GATEWAY=192.168.11.2

[root@localhost ~]#

验证

[root@localhost ~]# ifup eth0
Active connection state: activating
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/1
state: activated
Connection activated
[root@localhost ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:20:DA:65 
          inet addr:192.168.11.150  Bcast:192.168.11.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe20:da65/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:66 errors:0 dropped:0 overruns:0 frame:0
          TX packets:58 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:8384 (8.1 KiB)  TX bytes:5709 (5.5 KiB)

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:12 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:686 (686.0 b)  TX bytes:686 (686.0 b)

[root@localhost ~]# ping baidu.com
PING baidu.com (111.13.101.208) 56(84) bytes of data.
64 bytes from 111.13.101.208: icmp_seq=1 ttl=128 time=18.6 ms
^C
--- baidu.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 934ms
rtt min/avg/max/mdev = 18.627/18.627/18.627/0.000 ms
[root@localhost ~]#

克隆后网卡非eth0

ifconfig出现网卡不从eth0开始

正常来说,Linux在识别网卡时第一张会是eth0,第二张才是eth1。有时候我们使用虚拟机克隆技术后网卡的信息就会改变,新克隆出来的虚拟主机网卡名字可能变为eth1.无论我们怎么修改都无法改变。
在这里成这样是因为复制系统的过程中复制的文件已经有一个网卡在/etc/udev/rules.d/70-persistent-net.rules被识别成了eth0,而虚拟机中的识别成了eth1。
解决方法:

1.编辑/etc/udev/rules.d/70-persistent-net.rules,找到与ifconfig -a得出的MAC相同的一行(NAME=’eth1’这一行),把它改为”NAME=eth0 “,然后把上面一行(NAME=’eth0’)删除掉。

[root@redhat-client ~]# ifconfig  | grep HWaddr
eth1      Link encap:Ethernet  HWaddr 00:0C:29:78:6B:07 
[root@redhat-client ~]#
[root@redhat-client ~]# cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:20:da:65", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:78:6b:07", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
[root@redhat-client ~]#

修改之后

[root@redhat-client ~]# cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:78:6b:07", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
[root@redhat-client ~]#  

2.编辑/etc/sysconfig/network-script/ifcfg-eth0,把MAC改为正确的,把UUID删掉。

# ifconfig可以看到网卡的MAC地址为 00:0C:29:78:6B:07
HWADDR=00:0C:29:78:6B:07
sed -i "s/\(HWADDR=\).*$/\1\"$HWADDR\"/g" /etc/sysconfig/network-scripts/ifcfg-eth0

3.重启生效!

你可能感兴趣的:(RedHat)