如何给VPS的网卡增加IP(多IP)
临时方案
添加IP
ip address add 2202:b030:a42d:5dcd::1/64 dev eth0
删除IP
ip address del 2202:b030:a42d:5dcd::1/64 dev eth0
注意:
以上是命令行执行,网卡要与配置中的对应,不一定就是eth0永久方案(这里拿IPv6做演示,已知
/etc/network/interfaces
文件内容)auto lo iface lo inet loopback auto eth0 iface eth0 inet6 static address 2202:b030:a42d:5dcd::4b/64 # --- BEGIN PVE --- post-up ip route add 2202:b030:a42d:5d00::ffff dev eth0 post-up ip route add default via 2202:b030:a42d:5d00::ffff dev eth0 pre-down ip route del default via 2202:b030:a42d:5d00::ffff dev eth0 pre-down ip route del 2202:b030:a42d:5d00::ffff dev eth0 # --- END PVE --- auto eth1 iface eth1 inet static address 192.168.0.75/22 gateway 192.168.0.1
在配置文件中增加以下类似格式
auto eth0:2 iface eth0:2 inet6 static address 2202:b030:a42d:5dcd::2/64 auto eth0:3 iface eth0:3 inet6 static address 2202:b030:a42d:5dcd::3/64 auto eth0:4 iface eth0:4 inet6 static address 2202:b030:a42d:5dcd::4/64 auto eth0:5 iface eth0:5 inet6 static address 2202:b030:a42d:5dcd::5/64 auto eth0:6 iface eth0:6 inet6 static address 2202:b030:a42d:5dcd::6/64
然后重启网卡,如果重启网卡不生效可以重启服务器
ifdown eth0:2 && ifup eth0:2 ifdown eth0:3 && ifup eth0:3 ifdown eth0:4 && ifup eth0:4 ifdown eth0:5 && ifup eth0:5 ifdown eth0:6 && ifup eth0:6
查看IP添加情况
ifconfig
注意:
eth0 是 /etc/network/interfaces 中的 IPv6 对应的网卡,需要根据自己实际情况选择。
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
评论已关闭