Connect two interfaces via linux

1

i have two interfaces eth0 and wlan0. With wlan0 i am connected with an AP that has access to WAN, i receive an IP adress via DHCP coming from the AP.

A second interfacae is eth0. I configured it using an dhcp server giving out a different subnet ip adresses to all clients connected in that subnet via eth0.

My client device (smartphone) is getting an ip adress from my eth0 dhcp server correctly.

However I struggle to connect now eth0 with wlan0.

eth0 network is 192.168.42.0/24. My pc having both NICs uses 192.168.42.1. My ip adress from wlan0 is lets say 172.22.3.193

What I already did is enable ipv4 forwarding, but without success. My phone says there is no internet connection but can connect to eth0. It seems i have to setup certain iptables rules to get forwarding to work but I tried different approaches i could find in the net and none of it works.

Any ideas on what to do next?

Edit: My route command gives me this:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         www.go.wlantick 0.0.0.0         UG    600    0        0 wlan0
link-local      0.0.0.0         255.255.0.0     U     1000   0        0 eth0
172.22.0.0      0.0.0.0         255.255.0.0     U     600    0        0 wlan0
192.168.42.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0

tuxmania

Posted 2018-08-19T19:19:50.797

Reputation: 111

It seems to be a route issue. Can you provide the output of ip route command ? – vera – 2018-08-20T15:27:21.500

i added it in my original post – tuxmania – 2018-08-20T16:57:21.967

my bad, I did'nt state that you have not set up iptables – vera – 2018-08-21T09:00:04.020

Answers

0

To configure a linux server as NAT router, you have to :

  1. enable IP forwarding as you have already done (this is only ofr future reminder). Edit the following line in you /etc/sysctl.conf

    net.ipv4.ip_forward=1
    
  2. enable NAT with iptables. Please execute the following command, where wlan0 is your external interface.

    iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE 
    

Please remind that, iptables rules are reset at reboot. You uthen have to automate the reconfiguration of iptables.

vera

Posted 2018-08-19T19:19:50.797

Reputation: 760