Ubuntu-VPS使用额外IP
特殊情况下, 我们可能会需要在云服务器上部署多个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
- 原文作者:荸荠鸭
- 原文链接:https://duckgle.in/posts/Ubuntu-VPS%E4%BD%BF%E7%94%A8%E9%A2%9D%E5%A4%96IP/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。