linux修改網卡名稱、主機名
環境:virtualbox 5.0.14 + rhel 6.5
需求:個人實驗搭建一套standby rac時,為了節約時間,直接復制之前安裝rac的主機模板。
但復制之后發現網卡名稱不一致:
我這里的環境,primary rac的public ip和private ip分別對應的網卡名稱是eth2,eth3。
而復制standby rac的其中一臺網卡名稱是eth6,eth7;另一臺是eth4,eth5.為了保持一致方便后續管理維護,需要將standby rac的兩臺機器的網卡都統一改為eth2,eth3.
同樣的,復制的主機主機名是和之前一樣的,所以把主機名也修改一下。
以其中一臺為例: 首先查看主機目前的網絡情況,如下圖:
確認eth7的mac地址是:08:00:27:62:cc:7b
確認eth6的mac地址是:08:00:27:bc:1b:9f
然后在virtualbox的設置中,
根據mac地址確認eth6對應的是內部網絡(private ip);而eth7對應的是公有網絡(public ip)。
所以我們正確的做法應該是將eth6的名稱修改為eth3,將eth7的名稱修改為eth2.
注意:可能有些同學直接想當然的不確認mac地址直接修改錯了,這里一定要確認清楚,對于dba來說,任何做事情的細節都很重要。
1.首先修改/etc/udev/rules.d/70-persistent-net.rules文件:
將無關的網卡信息都刪除掉(如果怕誤操作也可不刪除,個人建議刪除,清楚且方便管理)
然后將eth6的名稱修改為eth3,將eth7的名稱修改為eth2。最終修改如下:
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@jyrac1 ~] # 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:0x100e (e1000) subsystem== "net" , action== "add" , drivers== "?*" , attr{address}== "08:00:27:bc:1b:9f" , attr{ type }== "1" , kernel== "eth*" , name= "eth3" # pci device 0x8086:0x100e (e1000) subsystem== "net" , action== "add" , drivers== "?*" , attr{address}== "08:00:27:62:cc:7b" , attr{ type }== "1" , kernel== "eth*" , name= "eth2" |
2.確認網絡ifcfg-ethn配置文件,并修改信息:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[root@jyrac1 network-scripts] # cat ifcfg-eth2 device=eth2 type =ethernet onboot= yes bootproto=static ipaddr=192.168.1.61 netmask=255.255.255.0 [root@jyrac1 network-scripts] # cat ifcfg-eth3 device=eth3 type =ethernet onboot= yes bootproto=static ipaddr=10.10.10.61 netmask=255.255.255.0 |
3.reboot重啟主機,網絡名稱成功修改并啟動正常,如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
[root@jyrac1 ~] # ifconfig -a eth2 link encap:ethernet hwaddr 08:00:27:62:cc:7b inet addr:192.168.1.61 bcast:192.168.1.255 mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe62:cc7b /64 scope:link up broadcast running multicast mtu:1500 metric:1 rx packets:377 errors:0 dropped:0 overruns:0 frame:0 tx packets:51 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 rx bytes:28101 (27.4 kib) tx bytes:6495 (6.3 kib) eth3 link encap:ethernet hwaddr 08:00:27: bc :1b:9f inet addr:10.10.10.61 bcast:10.10.10.255 mask:255.255.255.0 inet6 addr: fe80::a00:27ff:febc:1b9f /64 scope:link up broadcast running multicast mtu:1500 metric:1 rx packets:511 errors:0 dropped:0 overruns:0 frame:0 tx packets:12 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 rx bytes:46118 (45.0 kib) tx bytes:816 (816.0 b) 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:16436 metric:1 rx packets:4 errors:0 dropped:0 overruns:0 frame:0 tx packets:4 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 rx bytes:340 (340.0 b) tx bytes:340 (340.0 b) |
這樣,就可以通過securecrt連接到主機方便操作了。
下一步把主機名和/etc/hosts改一下:
主機名修改:
hostname jystdrac1 (臨時生效)
1
|
[root@jyrac1 network-scripts] # hostname jystdrac1 |
vi /etc/sysconfig/network (重啟生效)
1
2
3
|
[root@jyrac1 network-scripts] # vi /etc/sysconfig/network networking= yes hostname =jystdrac1 |
vi /etc/hosts (按照standby rac的規劃)
1
2
3
4
5
6
7
8
9
10
11
12
|
#public ip 192.168.1.61 jystdrac1 192.168.1.63 jystdrac2 #virtual ip 192.168.1.62 jystdrac1-vip 192.168.1.64 jystdrac2-vip #scan ip 192.168.1.65 jystdrac-scan #private ip 10.10.10.61 jystdrac1-priv 10.10.10.63 jystdrac2-priv |
重新登錄shell即可看到正確的主機名配置:
1
2
3
4
5
|
last login: wed aug 2 20:37:13 2017 from 192.168.1.88 [root@jystdrac1 ~] # [root@jystdrac1 ~] # hostname -i 192.168.1.61 [root@jystdrac1 ~] # |
至此,這個節點修改網卡名稱和主機名的工作就已經全部完成,另一個節點同樣方法修改即可。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:http://www.cnblogs.com/jyzhao/p/7277834.html?utm_source=tuicool&utm_medium=referral