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.

My debian system has the ip address 192.168.111.111 and I would like to configure a default gateway which is not on the 192.168.111.0 network. As a first step I want to add a route so that I can reach the gateway from the system. So I run this command (which I thought will enable a static route to a single host), but I still can't ping the gateway:

# ip route add 5.6.71.166 dev eth0
# ping 5.6.71.166
PING 5.6.71.166 (5.6.71.166) 56(84) bytes of data.
^C
--- 5.6.71.166 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 3023ms

Here's my configuration:

# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
5.6.71.166      0.0.0.0         255.255.255.255 UH        0 0          0 eth0
192.168.111.0   0.0.0.0         255.255.255.0   U         0 0          0 eth0

# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr ca:eb:7c:e6:7e:98  
          inet addr:192.168.111.111  Bcast:192.168.111.255  Mask:255.255.255.0
          inet6 addr: fe80::c8eb:7cff:fee6:7e98/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:45 errors:0 dropped:0 overruns:0 frame:0
          TX packets:291 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:52454 (51.2 KiB)  TX bytes:39433 (38.5 KiB)
          Interrupt:23 

# cat /etc/network/interfaces 
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The internal network interface
allow-hotplug eth0
iface eth0 inet static
address   192.168.111.111
netmask   255.255.255.0
network   192.168.111.0
broadcast 192.168.111.255

# cat /proc/sys/net/ipv4/ip_forward 
1

I have verified that the gateway will respond to ping if I use an IP address in its network, unfortunately that is not an option because the system can't have a real (not in 192.168.x.x) ip address in that range.

share|improve this question
    
Solved: the gateway also needs to reach the debian system, so it must have a route too: ip route add 192.168.111.111 dev eth0 . See comment below. –  nn4l Aug 21 '12 at 9:57

3 Answers 3

up vote 2 down vote accepted

Does your default-gateway-to-be know the way back to your machine?

Though you two (5.6.71.166 and 192.168.111.111) share a common layer2 ("ethernet") both must know how to reach each other. Normally, they share a common layer3 ("ip subnet"), but in this case the gw has to have a route to 192.168.111.111 (/24? at least /32) to it's device connected to the common l2.

Do you have administrative access to your gw?

share|improve this answer
    
This is correct. The router needs a route back to 192.168.111.0/24. –  bahamat Aug 14 '12 at 9:43
    
thanks, I was able to resolve the problem by adding the missing route on the gateway by running ip route add 192.168.111.111 dev eth0 –  nn4l Aug 21 '12 at 9:55

I'm assuming that 5.6.71.166 is on a different Ethernet domain. In order to communicate with hosts on a different Ethernet domain the host must use a gateway to get there. The route you've added specifies that 5.6.71.166 is directly reachable, which is why it is failing. You need to provide an appropriate gateway to use. Assuming that 192.168.111.1 is the gateway on the local network:

ip route add 5.6.71.166 via 192.168.111.1

If the 5.6.7.166 gateway is on the same Ethernet domain, it either doesn't know how to route packets back to your machine, or the packets are getting filtered somewhere. The gateway either needs a route for 192.168.111.0/24 on the local network, or you need to add an IP address to your machine which is in the gateway's local subnet.

Once that is setup check that ARP is working on both machines:

arp -n | grep 5.6.71.166

You should see a HWaddress listed. Do the same on the gateway for your machine's IP. If it still doesn't work check firewalls and possibly reverse path filtering.

share|improve this answer
    
The 5.6.71.166 server should be directly reachable as this system is connected to the same switch as 192.168.111.111. Also I don't have any router on the 192.168.111.0 network. –  nn4l Aug 14 '12 at 7:47
    
@mgorven: That's not necessarily a safe assumption. IP packets from different subnets can co-exist on the same ethernet domain and will pass "like ships in the night" unbeknownst to each other. After all, L2 has nothing to do with L3. –  bahamat Aug 14 '12 at 9:46
    
@bahamat Sure, but it's a less common configuration, hence my assumption in the face of insufficient information. –  mgorven Aug 14 '12 at 16:57

Can you add another IP address to eth0 iterface?

ifconfig eth0:1 5.6.71.167 netmask x.x.x.x up

then

route add default gw 5.6.71.166

Is it ok for you?

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.