Linux – How to ping through different interfaces (subnets) without using a router device

interfacelinuxroute

I have a big problem around this issue.

I want to be able to ping and access TFTP through my WIFI interface (wlan0) through my wired interface (eth0)

pc1_eth->LTdhcps2_eth0->LTdhcps2_wlan0->pc2_wlan

and the reverse

pc2_wlan->LTdhcps2_wlan0->LTdhcps2_eth0->pc1_eth

At first I thought that it would be simple because I assumed that I only need to set the gateway of my eth0 with my wlan0's IP.

I was wrong, I was unable to accomplish that.

Let the pain begins..

1) I think the configuration from pc1 and pc2 doesnt metter because it only involves the LTdhcps2 interfaces, am I right ?

Server LTdhcps2

Eth0

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 primary network interface
#allow-hotplug eth0
#iface eth0 inet dhcp

auto eth0
iface eth0 inet static
    address 192.168.2.10
    netmask 255.255.255.0

WLAN0

is DHCP configured by network-manager (I couldn't figured out how can I configure it using wpa_supplicant)

After starting the services

service network-manager start
service networking start

this the result

[root@LTdhcps2:~]# ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:1e:c9:24:c9:d1  
          inet addr:192.168.2.10  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:44 Base address:0xc000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:20 errors:0 dropped:0 overruns:0 frame:0
          TX packets:20 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1348 (1.3 KiB)  TX bytes:1348 (1.3 KiB)

wlan0     Link encap:Ethernet  HWaddr 00:24:2b:c7:74:7e  
          inet addr:10.0.2.218  Bcast:10.0.3.255  Mask:255.255.252.0
          inet6 addr: fe80::224:2bff:fec7:747e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:24154 errors:0 dropped:0 overruns:0 frame:37468
          TX packets:677 errors:8 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1670308 (1.5 MiB)  TX bytes:140171 (136.8 KiB)
          Interrupt:19

[root@LTdhcps2:~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.1.2        0.0.0.0         UG    0      0        0 wlan0
10.0.0.0        0.0.0.0         255.255.252.0   U     0      0        0 wlan0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0


[root@LTdhcps2:~]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         10.0.1.2        0.0.0.0         UG        0 0          0 wlan0
10.0.0.0        0.0.0.0         255.255.252.0   U         0 0          0 wlan0
192.168.2.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0

what I've tried to do.

[root@LTdhcps2:~]# route add -net 10.0.0.0 gw 10.0.2.218 dev eth0
SIOCADDRT: Invalid argument
[root@LTdhcps2:~]# 

Strange error that means nothing =| I googled and find this post: http://www.adminsehow.com/2011/09/gateway-on-a-different-subnet-on-linux/

it says that you have to add a host with the desired gateway IP because the gateway is in a different subnet.

[root@LTdhcps2:~]# route add -host 10.0.2.218/32 dev eth0
[root@LTdhcps2:~]# route add default gw 10.0.2.218

(if I put the dev eth0 at the end of the second command) it gives the SIOCADDRT: No such process error.

as result:

[root@LTdhcps2:~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         10.0.2.218      0.0.0.0         UG    0      0        0 wlan0
default         10.0.1.2        0.0.0.0         UG    0      0        0 wlan0
10.0.0.0        *               255.255.252.0   U     0      0        0 wlan0
10.0.2.218      *               255.255.255.255 UH    0      0        0 eth0
192.168.2.0     *               255.255.255.0   U     0      0        0 eth0

[root@LTdhcps2:~]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         10.0.2.218      0.0.0.0         UG        0 0          0 wlan0
0.0.0.0         10.0.1.2        0.0.0.0         UG        0 0          0 wlan0
10.0.0.0        0.0.0.0         255.255.252.0   U         0 0          0 wlan0
192.168.2.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0

But I was unable to ping/traceroute wlan0 using the eth0 interface or its gateway (10.0.1.2)

[root@LTdhcps2:~]# ping -I eth0 10.0.2.218
PING 10.0.2.218 (10.0.2.218) from 192.168.2.10 eth0: 56(84) bytes of data.
From 192.168.2.10 icmp_seq=1 Destination Host Unreachable
From 192.168.2.10 icmp_seq=2 Destination Host Unreachable

[root@LTdhcps2:~]# ping -I eth0 10.0.1.2
PING 10.0.1.2 (10.0.1.2) from 192.168.2.10 eth0: 56(84) bytes of data.
From 192.168.2.10 icmp_seq=1 Destination Host Unreachable
From 192.168.2.10 icmp_seq=2 Destination Host Unreachable

[root@LTdhcps2:~]# traceroute -i  eth0 10.0.2.218
traceroute to 10.0.2.218 (10.0.2.218), 30 hops max, 60 byte packets
 1  * * *
 2  * * *
 3  * * *
 4  * * *

Sorry for the long post and bad English. I'm facing this problem the holy week =|

Best Answer

I solved the question.

ping -I interface or traceroute -i interface

They aren't the way to check if its working, you don't need to specif the interface because if you do the kernel doesn't use the route table (I guess).