Debian – How to add gateway to debian system on private network

debiannetworking

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.

Best Answer

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?