特殊情况下, 我们可能会需要在云服务器上部署多个IP.

编辑 /etc/network/interface .

多网卡版

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
	address 192.168.1.200
	netmask 255.255.255.0
	gateway 192.168.1.1
	up ip route add default table 100 dev $IFACE via 192.168.1.1
	up ip rule add from 192.168.1.200/32 table 100
	up ip rule add to 192.168.1.200/32 table 100
	down ip rule del to 192.168.1.200/32
	down ip rule del from 192.168.1.200/32
	down ip route del default table 100 via 192.168.1.200

auto eth1
iface eth1 inet static
	address 192.168.2.200
	netmask 255.255.255.0
	gateway 192.168.2.1
	up ip route add default table 101 dev $IFACE via 192.168.2.1
	up ip rule add from 192.168.2.200/32 table 101
	up ip rule add to 192.168.2.200/32 table 101
	down ip rule del to 192.168.2.200/32
	down ip rule del from 192.168.2.200/32
	down ip route del default table 101 via 192.168.2.200

auto eth2
iface eth2 inet static
	address 192.168.3.200
	netmask 255.255.255.0
	gateway 192.168.3.1
	up ip route add default table 102 dev $IFACE via 192.168.3.1
	up ip rule add from 192.168.3.200/32 table 102
	up ip rule add to 192.168.3.200/32 table 102
	down ip rule del to 192.168.3.200/32
	down ip rule del from 192.168.3.200/32
	down ip route del default table 102 via 192.168.3.200

单网卡+单网关版

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
	address 192.168.1.200
	netmask 255.255.255.0
	gateway 192.168.1.1
	up ip route add default table 100 dev $IFACE via 192.168.1.1
	up ip rule add from 192.168.1.200/32 table 100
	up ip rule add to 192.168.1.200/32 table 100
	down ip rule del to 192.168.1.200/32
	down ip rule del from 192.168.1.200/32
	down ip route del default table 100 via 192.168.1.200

auto eth0:1
iface eth0 inet static
	address 192.168.1.201
	netmask 255.255.255.0
	gateway 192.168.1.1
	up ip route add default table 101 dev $IFACE via 192.168.1.1
	up ip rule add from 192.168.1.201/32 table 101
	up ip rule add to 192.168.1.201/32 table 101
	down ip rule del to 192.168.1.201/32
	down ip rule del from 192.168.1.201/32
	down ip route del default table 101 via 192.168.1.201

auto eth0:2
iface eth0 inet static
	address 192.168.1.202
	netmask 255.255.255.0
	gateway 192.168.1.1
	up ip route add default table 102 dev $IFACE via 192.168.1.1
	up ip rule add from 192.168.1.202/32 table 102
	up ip rule add to 192.168.1.202/32 table 102
	down ip rule del to 192.168.1.202/32
	down ip rule del from 192.168.1.202/32
	down ip route del default table 102 via 192.168.1.202

auto eth0:3
iface eth0 inet static
	address 192.168.1.203
	netmask 255.255.255.0
	gateway 192.168.1.1
	up ip route add default table 103 dev $IFACE via 192.168.1.1
	up ip rule add from 192.168.1.203/32 table 103
	up ip rule add to 192.168.1.203/32 table 103
	down ip rule del to 192.168.1.203/32
	down ip rule del from 192.168.1.203/32
	down ip route del default table 103 via 192.168.1.203