在CentOS 7阿里雲服務器把IP地址和MAC地址綁定,網上起初搜索到的方法都不行。如下是後來根據報錯搜索到的結果。docker
其實,到底有沒有綁定成功我也不太肯定。雖然,執行「arp」命令、「arp -a」命令都能找到綁定記錄,但我仍是不放心。bash
[root@iZ236166figZ ~]# ifconfig docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.0.1 netmask 255.255.240.0 broadcast 0.0.0.0 ether 02:42:c4:da:39:9e txqueuelen 0 (Ethernet) RX packets 90553 bytes 9116677 (8.6 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 130887 bytes 195002426 (185.9 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.253.43.165 netmask 255.255.248.0 broadcast 10.253.47.255 ether 00:16:3e:00:0d:b7 txqueuelen 1000 (Ethernet) RX packets 1705153533 bytes 384820555809 (358.3 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 589976960 bytes 480870664184 (447.8 GiB) TX errors 0 dropped 11 overruns 0 carrier 0 collisions 0 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 118.178.12.16 netmask 255.255.254.0 broadcast 118.178.13.255 ether 00:16:3e:00:07:5e txqueuelen 1000 (Ethernet) RX packets 5530935427 bytes 256025183196 (238.4 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 48853685 bytes 27799365139 (25.8 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 loop txqueuelen 0 (Local Loopback) RX packets 12958790 bytes 832306490 (793.7 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 12958790 bytes 832306490 (793.7 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
綁定IP地址和MAC地址:服務器
[root@iZ236166figZ ~]# arp -s 10.253.43.165 -H ether 00:16:3e:00:0d:b7 -i eth0 [root@iZ236166figZ ~]# arp -s 118.178.12.16 -H ether 00:16:3e:00:07:5e -i eth1
加入開機自啓動項:ide
[root@iZ236166figZ ~]# echo "arp -s 10.253.43.165 -H ether 00:16:3e:00:0d:b7 -i eth0" >>/etc/rc.local [root@iZ236166figZ ~]# echo "arp -s 118.178.12.16 -H ether 00:16:3e:00:07:5e -i eth1" >>/etc/rc.local [root@iZ236166figZ ~]# cat /etc/rc.local #!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own systemd services or udev rules # to run scripts during boot instead of using this file. # # In contrast to previous versions due to parallel execution during boot # this script will NOT be run after all other services. # # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure # that this script will be executed during boot. touch /var/lock/subsys/local arp -s 10.253.43.165 -H ether 00:16:3e:00:0d:b7 -i eth0 arp -s 118.178.12.16 -H ether 00:16:3e:00:07:5e -i eth1
CentOS 7以後,/etc/rc.local文件通常須要增長執行權限,才能在重啓服務器後,運行裏面的命令。oop
[root@iZ236166figZ ~]# ll /etc/rc.d/rc.local -rw-r--r-- 1 root root 585 Aug 5 14:51 /etc/rc.d/rc.local [root@iZ236166figZ ~]# chmod +x /etc/rc.d/rc.local [root@iZ236166figZ ~]# ll /etc/rc.d/rc.local -rwxr-xr-x 1 root root 585 Aug 5 14:51 /etc/rc.d/rc.local