Using Linux route command to configure WiFi for testing


#1

I have a Linux box connected with Ethernet. When I enabled WiFi and Ethernet at the same time, the Linux box did not automatically set up the route for THETA.

Assuming your THETA assigns an IP address of 192.168.1.5 to your Linux box WiFi adapter, here’s how to set up the route.

$ sudo route add 192.168.1.1 gw 192.168.1.5

Explanation

The THETA is 192.168.1.1
The Linux box WiFi adapter is 192.168.1.5
The default gateway of my office is on the same 192.168.1.0 subnet
Command above will route any traffic to 192.168.1.1 (the THETA) through 192.168.1.5 (the WiFi card on the Linux box)

Finding IP addresses

run ifconfig

$ ifconfig
enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.116  netmask 255.255.255.0  broadcast 192.168.1.255

wlx000f6009a377: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.5  netmask 255.255.255.0  broadcast 192.168.1.255

My Ethernet card is at 192.168.1.116
My WiFi card is at 192.168.1.5

Testing

$ ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
From 192.168.1.116 icmp_seq=1 Destination Host Unreachable

$ sudo route add 192.168.1.1 gw 192.168.1.5

$ ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=255 time=1075 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=255 time=60.0 ms