在CentOS 7阿里云服务器把IP地址和MAC地址绑定,网上起初搜索到的方法都不行。以下是后来根据报错搜索到的结果。

  其实,到底有没有绑定成功我也不太确定。虽然,执行“arp”命令、“arp -a”命令都能找到绑定记录,但我还是不放心。

[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

  加入开机自启动项:

[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文件一般需要增加执行权限,才能在重启服务器后,运行里面的命令。

[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