0

I am trying to share VPN connection with LAN and WLAN. Set up static DHCP IP on both LAN and WLAN, using phone as USB internet tethering.

Everything works when sharing usb0 connection(as only internet connection, not with VPN) to eth0 and wlan0. However, when using nordvpn connect in terminal, for a short period internet connection on devices is ok, but then internet is not accessible on other device , but on main computer with VPN it works. Only by disconnecting nordvpn and reconnecting and reapplying the commands it works, again for a short period. This is how my tun0 looks like, with the inet IP changing with every connect:inet 10.8.3.2 netmask 255.255.255.0 destination 10.8.3.2, then using the commands sharing VPN connection:

iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
iptables -A FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0 -o tun0 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

I suspect it has something to do with the route table because when adding default tun0 ip address it works again, but only for a while then tun0 IP inet is changing and have to do all over again. This is the route table (ip of tun0 is not always the same):

default         10.8.0.8        0.0.0.0         UG    0      0        0 tun0
default         192.168.42.129  0.0.0.0         UG    204    0        0 usb0
10.8.0.0        0.0.0.0         255.255.255.0   U     0      0        0 tun0
link-local      0.0.0.0         255.255.0.0     U     205    0        0 eth1
192.168.2.0     0.0.0.0         255.255.255.0   U     202    0        0 eth0
192.168.4.0     0.0.0.0         255.255.255.0   U     303    0        0 wlan0
192.168.42.0    0.0.0.0         255.255.255.0   U     204    0        0 usb0
unn-195-181-170 192.168.42.129  255.255.255.255 UGH   0      0        0 usb0

The last unn-195-181-170 192.168.42.129 255.255.255.255 UGH 0 0 0 usb0 part only recently appeared because the main route table was flushed as a failed attempt to fix the problem, usually it is not appearing. With iptables -S :

-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i eth0 -o tun0 -j ACCEPT
-A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -j ACCEPT

Sometimes at end it shows like usb0 -j DROP, wlan0 -j DROP and eth0 -j DROP . On tun0 if it does not exist, above iptables are not working and only by reapplying them they work, but again for a short period. If understood correctly, it has something to do with the inet IP of tun0 changing but how to make it static so that there is no need to reapply everything, don't know. I am a beginner in all of this and appreciate any help. Hope someone can point me into the right direction.

Edit: Just noticed that I left in iptables -S from a different setup table. This one is now correct

4
  • it's good explaining but wrong site, please transfer the question to superuser
    – djdomi
    May 23, 2021 at 20:50
  • @djdomi Thanks, should I then delete this one and open a new question on superuser, or can it be literally transferred?
    – daniell212
    May 24, 2021 at 12:28
  • you can flag your question with community reasons and click on blond to a other site
    – djdomi
    May 24, 2021 at 13:04
  • @Dave M does this mean the question should stay here?
    – daniell212
    May 27, 2021 at 16:07

1 Answer 1

0

This is a repeat of my question at: VPN connection not accessible on network

I found a workaround which was explained in the post.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .