Ubutun设置多个ip
# The loopback interface
auto lo
iface lo inet loopback
# Configuration for eth0 and aliases
# This line ensures that the interface will be brought up during boot.
auto eth0 eth0:0 eth0:1
# eth0 - This is the main IP address that will be used for most outbound connections.
# The address, netmask and gateway are all necessary.
iface eth0 inet static
address 12.34.56.78
netmask 255.255.255.0
gateway 12.34.56.1
# eth0:0
# This is a second public IP address.
iface eth0:0 inet static
address 34.56.78.90
netmask 255.255.255.0
# eth0:1 - Private IPs have no gateway (they are not publicly routable) so all you need to
# specify is the address and netmask.
iface eth0:1 inet static
address 192.168.133.234
netmask 255.255.128.0
添加以上配置的时候注意原有的配置文件要注释掉
重启网络
/etc/init.d/networking restart
重复这个命令可能会碰到错误,resolvconf: Error: /etc/resolv.conf isn’t a symlink, not doing anything.
我的系统是ubuntu 12.04
办法
mv /etc/resolv.conf /run/resolvconf/resolv.conf
ln -s /run/resolvconf/resolv.conf /etc/resolv.conf
然后就可以了
Once you have confirmed that your networking settings have been correctly configured, issue the following command to uninstall the DHCP client, as it is no longer required.
apt-get remove isc-dhcp-client dhcp3-client dhcpcd
参考: https://library.linode.com/networking/configuring-static-ip-interfaces#sph_debian-and-ubuntu
同时不要忘记添加 vi /etc/resolv.conf
但是好像重启后该文件又被重写了?暂时没找到办法
DNS Resolver Settings
nameserver 98.76.54.32
nameserver 76.54.32.10
options rotate