Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I would like my Ubuntu VM to have both a private IP and a public IP. The private IP should be supplied by my DHCP server.

Currently I am trying this:

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

The problem is that I can only ping the private IP address, not the public one. When I bring eth0 down I can start pinging the public IP address. So it seems that somehow DHCP is preventing my public IP address from working correctly?

ip route shows:

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

the routes on my 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
share|improve this question
    
Is the public interface also on the 109.x network? –  Mike Fiedler Dec 15 '13 at 16:21
    
eth1 is on the 109.x network –  Jochen Dec 15 '13 at 16:26
    
And the routes on your host machine? –  Mike Fiedler Dec 15 '13 at 16:34

2 Answers 2

I had to add this to /etc/network/interfaces (in the eth0 section)

up route add -net 192.168.159.0 netmask 255.255.255.0 gw 192.168.168.254 dev eth0
share|improve this answer
    
You added a route to your private network which fixed a problem ping the public IP from localhost? So now DHCP does not change the metric for your public IP? –  rjt Dec 15 '13 at 16:58

The main problem is you receive default gateway by DHCP which is established with minimal metric 0. You can not reach public IPs since packets go to the private network.

Try to disable gateway in DHCP.

FYI: SE/Superuser: I don't want my DHCP to be a default gateway

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.