How to route between 2 connections (different network) in 1 PC (wired & wireless card)?

I have a problem to make a routing table for my PC.

I have 1 pc running on Ubuntu, and i have 2 connection card (eth0 & wlan0). eth0 IP : 192.168.1.1/24 wlan0 IP: 10.10.10.1/24 with dhcp-server installed

client with IP: 10.10.10.2 connected to my router wlan0 but not connected to my eth0 network.

How to solve this problem? thanks


Solution 1:

I see both networks have private IPs so I will assume you just want to route traffic between those two; no firewalling, no traffic control of any kind, no network address translation.

Try doing this:

echo "1" | sudo tee /proc/sys/net/ipv4/ip_forward

then ensure your client (10.10.10.2) has its default gateway set to 10.10.10.1 (your Linux box/router).

Once you have this, you should be able to see the other network (192.168.1.0). To test this, try pinging the Linux box's address on that network (192.168.1.1). You should get a response:

$ 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_req=1 ttl=64 time=2.30 ms
64 bytes from 192.168.1.1: icmp_req=2 ttl=64 time=1.62 ms

The ip_forward setting tells the Linux kernel to forward packets destined for another network through the appropriate interface. By default it's turned off, meaning that the kernel will discard packets that are asking to be forwarded.

This setting will "reset" itself when you reboot the system, to make it permanent do this:

echo "net.ipv4.ip_forward=1" | sudo tee /etc/sysctl.d/60-ip-forward.conf

This will create a config file with this setting to be loaded when the system boots.

Finally, please read the IP Tables Howto which contains information on how to control how your kernel allows packets to pass through the interfaces, whether it does network address translation, and other things. This is very important if you ever want to have a Linux system sitting between a public network and a private one (and even between two private networks, as forwarding traffic may not always be desired in this case).