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),刪除掉重復的