如何配置双IP

云服务器

如何配置双IP

2025-05-04 14:48


                                            




  1. 执行如下命令,修改/etc/iproute2/rt_tables配置文件,新增路由表。
    vim /etc/iproute2/rt_tables

    以eth1和eth2为例增加如下内容,如下图红框所示。

    251    eth1
    252    eth2

  2. 将路由信息永久写入/etc/rc.local文件,保证云主机重启后扩展网卡的路由仍然生效。

    信息永久写入/etc/rc.local文件,保证云主机重启后扩展网卡的路由仍然生效。
    vim /etc/rc.local

    以eth1和eth2为例,添加以下内容,如下图红框所示。其中ip route flush table命令用于清空路由表。

    ip route flush table eth1   
    ip route add default via 192.168.0.1 dev eth1 src 192.168.0.20 table eth1
    ip rule add from 192.168.0.20 table eth1
    
    ip route flush table eth2
    ip route add default via 192.168.0.1 dev eth2 src 192.168.0.179 table eth2
    ip rule add from 192.168.0.179 table eth2

標簽:
  • 双IP配置教程