通过DHCP +公共IP分配专用IP

我希望我的Ubuntu虚拟机拥有私有IP和公有IP。 私人IP应该由我的DHCP服务器提供。

目前我正在尝试这个:

auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet dhcp auto eth1 iface eth1 inet static address 109.68.162.166 netmask 255.255.255.240 network 109.68.162.160 broadcast 109.68.162.175 gateway 109.68.162.174 

问题是我只能ping私人IP地址,而不是公共的IP地址。 当我把eth0closures时,我可以开始ping公共IP地址。 所以看来,不知何故DHCP阻止我的公共IP地址正常工作?

ip路由显示:

 default via 192.168.168.254 dev eth0 default via 109.68.162.174 dev eth1 metric 100 109.68.162.160/28 dev eth1 proto kernel scope link src 109.68.162.166 192.168.160.0/20 dev eth0 proto kernel scope link src 192.168.164.96 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.168.254 0.0.0.0 UG 0 0 0 eth0 0.0.0.0 109.68.162.174 0.0.0.0 UG 100 0 0 eth1 109.68.162.160 0.0.0.0 255.255.255.240 U 0 0 0 eth1 192.168.160.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0 

我的vmhost上的路线:

 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.168.254 0.0.0.0 UG 0 0 0 br925 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 192.168.160.0 0.0.0.0 255.255.240.0 U 0 0 0 br925 

主要的问题是您通过DHCP以最小度量0build立默认网关。由于数据包进入专用networking,您无法访问公共IP。

尝试在DHCP中禁用网关。

FYI: SE /超级用户: 我不希望我的DHCP成为默认网关

我不得不把它添加到/ etc / network / interfaces(在eth0部分)

 up route add -net 192.168.159.0 netmask 255.255.255.0 gw 192.168.168.254 dev eth0