如何控制具有多个具有静态IP地址的接口的路由
我正在制作一个Ubuntu LTS 16.04.2 LTS服务器盒。 该服务器有3个接口,Public(ETH0),Private(ETH1),Management(ETH2)。 该服务器有3个静态IP地址。
在配置的接口之间,默认路由有时会从引导更改为引导。 我想让Ubuntu使用我配置的默认路由,而不是它认为它想要使用的路由。 无论如何它在哪里获得默认路线?
通常我把它放在/ etc / network / interfaces配置中,但我不习惯在具有多个接口的配置中工作。 我有UP ROUTE ..命令,有时它们被设置,有时不设置。 它们位于配置的末尾,但尝试将它们移动到接口配置下,没有运气。
我试过POST-UP,结果相同。 我已经尝试将它放在rc.local中但不起作用。 有时路由出现在netstat -r,route,route -n,无论你想要使用什么命令,有时它们不会。 它似乎取决于启动时框选择的默认路由。
我如何告诉Ubuntu根本不创建任何路由,但使用我提供的表…? 基本上,将0.0.0.0 0.0.0.0发送到Eth0和静态路由Eth2,例如路由10.100.0.0 netmask 255.255.0.0 dev eth2
我可以手动完成所有操作,但希望它在重新启动之间持久且一致。
resolv.conf与这里的任何东西有什么关系?
谢谢。
开始吧
拓扑
--------- | pc1 | --- 192.168.0.10 ------ 192.168.0.250/eth1-- | --------- | ---------私人| | | 服务器| --172.20.20.20 / eth0 --------- | | 上市 | pc2 | --- 192.168.1.10 ------ 192.168.1.250/eth2-- | --------- | ---------管理
就像我说的,如果你的服务器不需要通过eth1
通信,除了来自192.168.0.0/24
网络的机器,如果不需要通过eth2
进行通信,除了来自192.168.1.0/24
网络的机器,你不需要在这个接口上使用网关。 配置很好
#环回网络接口 汽车公司 iface lo inet loopback 自动eth0 iface eth0 inet static 地址172.20.20.250 网络掩码255.255.255.0 网关172.20.20.1 汽车eth1 iface eth1 inet static 地址192.168.0.250 网络掩码255.255.255.0 自动eth2 iface eth2 inet static 地址192.168.2.250 网络掩码255.255.255.0
添加更多路由到某个界面
#环回网络接口 汽车公司 iface lo inet loopback 自动eth0 iface eth0 inet static 地址172.20.20.250 网络掩码255.255.255.0 网关172.20.20.1 汽车eth1 iface eth1 inet static 地址192.168.0.250 网络掩码255.255.255.0 up route add -net 192.168.18.0/24 dev eth1 自动eth2 iface eth2 inet static 地址192.168.2.250 网络掩码255.255.255.0
或者,如果您需要在接口上使用网关,则可以添加指标。 具有较少度量的接口具有优先级
#环回网络接口 汽车公司 iface lo inet loopback 自动eth0 iface eth0 inet static 地址172.20.20.250 网络掩码255.255.255.0 网关172.20.20.1 汽车eth1 iface eth1 inet static 地址192.168.0.250 网络掩码255.255.255.0 网关192.168.0.1 公制400 up route add -net 192.168.18.0/24 dev eth1 自动eth2 iface eth2 inet static 地址192.168.2.250 网络掩码255.255.255.0 网关192.168.2.1 公制800
这是配置的示例。 改变您的IP网络,指标,每个接口的路由….
当您执行配置保存/etc/network/interfaces
,请重新启动网络
sudo service networking restart
或者你可以重启server