ubuntu服务器采集多IP段
⑴ 如何给Ubuntu网站绑定多个IP,怎么给Ubuntu服务器设置多IP
多个不同IP段的 /etc/network/interfaces 配置文件的范例如下:
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 8.8.8.2
netmask 255.255.255.248
gateway 8.8.8.1 要注意这里,多个不同IP段,只要1个gateway配置即可,其他IP不需要配置gateway
auto eth0:0
iface eth0:0 inet static
address 8.8.8.3
netmask 255.255.255.248
auto eth0:1
iface eth0:1 inet static
address 8.8.8.4
netmask 255.255.255.248
auto eth0:2
iface eth0:2 inet static
address 8.8.8.5
netmask 255.255.255.248
auto eth0:3
iface eth0:3 inet static
address 8.8.8.6
netmask 255.255.255.248
auto eth0:4
iface eth0:4 inet static
address 6.6.6.130 注意这里,虽然这是不同的IP段,但是不需要配置gateway,只需要配置netmask即可
netmask 255.255.255.224
auto eth0:5
iface eth0:5 inet static
address 6.6.6.131
netmask 255.255.255.224
更多ip也类似配置即可。
配置文件完成后,用命令 /etc/init.d/networking restart 重启网络,不需要reboot重启服务器。 /etc/init.d/networking restart 重启网络的时候,如果你的配置文件有错误,那么他会提示你。比如IP重复了,书写错误了,等等。在执行此命令前,一定要小心检查interfaces配置文件,不然可能就把网络弄瘫痪,那时候就需要机房的工作人员去处理,十分麻烦。
/etc/init.d/networking restart错误分析案例:
[email protected]:/etc/network# /etc/init.d/networking restart
* Reconfiguring network interfaces...
/etc/network/interfaces:165: interface eth0:28 declared allow-auto twice
ifdown: couldn't read interfaces file "/etc/network/interfaces"
/etc/network/interfaces:165: interface eth0:28 declared allow-auto twice
ifup: couldn't read interfaces file "/etc/network/interfaces"
...fail!
说明eth0:28有重复,解决办法:vi interfaces找到eth0:28,删除掉重复的
[email protected]:/etc/network# /etc/init.d/networking restart
* Reconfiguring network interfaces...
/etc/network/interfaces:166: plicate interface
ifdown: couldn't read interfaces file "/etc/network/interfaces"
/etc/network/interfaces:166: plicate interface
ifup: couldn't read interfaces file "/etc/network/interfaces"
...fail!
说明166行有重复,解决办法:vi interfaces找到166行(set number),删除掉重复的
[email protected]:/etc/network# /etc/init.d/networking restart
* Reconfiguring network interfaces...
/etc/network/interfaces:162: plicate interface
ifdown: couldn't read interfaces file "/etc/network/interfaces"
/etc/network/interfaces:162: plicate interface
ifup: couldn't read interfaces file "/etc/network/interfaces"
说明162行有重复,解决办法:vi interfaces找到166行(set number),删除掉重复的