Check then your current iptables with iptables-save.
If you run into problems just reboot.
If everything looks fine and functions as expected, make it persistent with:
iptables-save > /etc/iptables/rules.v4
If you use ipv6 you have to use ip6tables, ip6tables-save and rules.v6.
Because you deleted the rules, that was what you asked for
Can you please share more info about your setup and what you want to achieve?
Your route to the Internet is via eth0 and you want to connect devices via wifi, but they should be tunneld though a VPN?
And is this right that you have several tunnel interfaces, wg0 and tun 1?
So Internet access is via eth0…
And I want to connect devices via wlan0 (hotspot) and only these devices/this traffic should be routed via tun1 (VPN tunnel). The standard traffic should be routed via eth0 without tunneling.
My devices are
eth0: Internet acces
wg0: wireguard server from outside
wlan0: hotspot
tun0: open vpn server currently unused
tun1: open vpn client
# ip -4 addr; ip -4 ro list table all; ip -4 ru; iptables-save -c
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 192.168.178.25/24 brd 192.168.178.255 scope global dynamic eth1
valid_lft 811184sec preferred_lft 811184sec
4: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
inet 192.168.42.1/24 brd 192.168.42.255 scope global wlan0
valid_lft forever preferred_lft forever
5: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 500
inet 10.8.0.1 peer 10.8.0.2/32 scope global tun0
valid_lft forever preferred_lft forever
6: wg0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN group default qlen 1000
inet 10.9.0.1/24 scope global wg0
valid_lft forever preferred_lft forever
default via 192.168.178.1 dev eth1
10.8.0.0/24 via 10.8.0.2 dev tun0
10.8.0.2 dev tun0 proto kernel scope link src 10.8.0.1
10.9.0.0/24 dev wg0 proto kernel scope link src 10.9.0.1
192.168.42.0/24 dev wlan0 proto kernel scope link src 192.168.42.1
192.168.178.0/24 dev eth1 proto kernel scope link src 192.168.178.25
local 10.8.0.1 dev tun0 table local proto kernel scope host src 10.8.0.1
broadcast 10.9.0.0 dev wg0 table local proto kernel scope link src 10.9.0.1
local 10.9.0.1 dev wg0 table local proto kernel scope host src 10.9.0.1
broadcast 10.9.0.255 dev wg0 table local proto kernel scope link src 10.9.0.1
broadcast 127.0.0.0 dev lo table local proto kernel scope link src 127.0.0.1
local 127.0.0.0/8 dev lo table local proto kernel scope host src 127.0.0.1
local 127.0.0.1 dev lo table local proto kernel scope host src 127.0.0.1
broadcast 127.255.255.255 dev lo table local proto kernel scope link src 127.0.0.1
broadcast 192.168.42.0 dev wlan0 table local proto kernel scope link src 192.168.42.1
local 192.168.42.1 dev wlan0 table local proto kernel scope host src 192.168.42.1
broadcast 192.168.42.255 dev wlan0 table local proto kernel scope link src 192.168.42.1
broadcast 192.168.178.0 dev eth1 table local proto kernel scope link src 192.168.178.25
local 192.168.178.25 dev eth1 table local proto kernel scope host src 192.168.178.25
broadcast 192.168.178.255 dev eth1 table local proto kernel scope link src 192.168.178.25
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
# Generated by iptables-save v1.8.9 (nf_tables) on Mon Jan 29 13:36:33 2024
*filter
:INPUT ACCEPT [68564:10386972]
:FORWARD ACCEPT [560:186445]
:OUTPUT ACCEPT [52917:8337927]
[147492:158813905] -A FORWARD -i eth1 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
[48534:9407481] -A FORWARD -i wlan0 -o eth1 -j ACCEPT
[608:64791] -A FORWARD -i wg0 -j ACCEPT
COMMIT
# Completed on Mon Jan 29 13:36:33 2024
# Generated by iptables-save v1.8.9 (nf_tables) on Mon Jan 29 13:36:33 2024
*nat
:PREROUTING ACCEPT [13587:1250914]
:INPUT ACCEPT [9099:579438]
:OUTPUT ACCEPT [19353:1460497]
:POSTROUTING ACCEPT [5176:348107]
[18430:1698413] -A POSTROUTING -o eth1 -j MASQUERADE
[0:0] -A POSTROUTING -s 192.168.42.0/24 -o eth1 -j MASQUERADE
[0:0] -A POSTROUTING -s 10.9.0.0/24 -o eth1 -j MASQUERADE
COMMIT
# Completed on Mon Jan 29 13:36:33 2024
vpn client started:
# ip -4 addr; ip -4 ro list table all; ip -4 ru; iptables-save -c
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 192.168.178.25/24 brd 192.168.178.255 scope global dynamic eth1
valid_lft 811092sec preferred_lft 811092sec
4: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
inet 192.168.42.1/24 brd 192.168.42.255 scope global wlan0
valid_lft forever preferred_lft forever
5: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 500
inet 10.8.0.1 peer 10.8.0.2/32 scope global tun0
valid_lft forever preferred_lft forever
6: wg0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN group default qlen 1000
inet 10.9.0.1/24 scope global wg0
valid_lft forever preferred_lft forever
7: tun1: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 500
inet 10.6.19.10/24 scope global tun1
valid_lft forever preferred_lft forever
0.0.0.0/1 via 10.6.19.1 dev tun1
default via 192.168.178.1 dev eth1
10.6.19.0/24 dev tun1 proto kernel scope link src 10.6.19.10
10.8.0.0/24 via 10.8.0.2 dev tun0
10.8.0.2 dev tun0 proto kernel scope link src 10.8.0.1
10.9.0.0/24 dev wg0 proto kernel scope link src 10.9.0.1
31.171.154.136 via 192.168.178.1 dev eth1
128.0.0.0/1 via 10.6.19.1 dev tun1
192.168.42.0/24 dev wlan0 proto kernel scope link src 192.168.42.1
192.168.178.0/24 dev eth1 proto kernel scope link src 192.168.178.25
broadcast 10.6.19.0 dev tun1 table local proto kernel scope link src 10.6.19.10
local 10.6.19.10 dev tun1 table local proto kernel scope host src 10.6.19.10
broadcast 10.6.19.255 dev tun1 table local proto kernel scope link src 10.6.19.10
local 10.8.0.1 dev tun0 table local proto kernel scope host src 10.8.0.1
broadcast 10.9.0.0 dev wg0 table local proto kernel scope link src 10.9.0.1
local 10.9.0.1 dev wg0 table local proto kernel scope host src 10.9.0.1
broadcast 10.9.0.255 dev wg0 table local proto kernel scope link src 10.9.0.1
broadcast 127.0.0.0 dev lo table local proto kernel scope link src 127.0.0.1
local 127.0.0.0/8 dev lo table local proto kernel scope host src 127.0.0.1
local 127.0.0.1 dev lo table local proto kernel scope host src 127.0.0.1
broadcast 127.255.255.255 dev lo table local proto kernel scope link src 127.0.0.1
broadcast 192.168.42.0 dev wlan0 table local proto kernel scope link src 192.168.42.1
local 192.168.42.1 dev wlan0 table local proto kernel scope host src 192.168.42.1
broadcast 192.168.42.255 dev wlan0 table local proto kernel scope link src 192.168.42.1
broadcast 192.168.178.0 dev eth1 table local proto kernel scope link src 192.168.178.25
local 192.168.178.25 dev eth1 table local proto kernel scope host src 192.168.178.25
broadcast 192.168.178.255 dev eth1 table local proto kernel scope link src 192.168.178.25
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
# Generated by iptables-save v1.8.9 (nf_tables) on Mon Jan 29 13:38:06 2024
*filter
:INPUT ACCEPT [68874:10430641]
:FORWARD ACCEPT [560:186445]
:OUTPUT ACCEPT [53142:8367240]
[147492:158813905] -A FORWARD -i eth1 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
[48534:9407481] -A FORWARD -i wlan0 -o eth1 -j ACCEPT
[608:64791] -A FORWARD -i wg0 -j ACCEPT
COMMIT
# Completed on Mon Jan 29 13:38:06 2024
# Generated by iptables-save v1.8.9 (nf_tables) on Mon Jan 29 13:38:06 2024
*nat
:PREROUTING ACCEPT [13596:1251619]
:INPUT ACCEPT [9108:580143]
:OUTPUT ACCEPT [19403:1463888]
:POSTROUTING ACCEPT [5191:349075]
[18465:1700836] -A POSTROUTING -o eth1 -j MASQUERADE
[0:0] -A POSTROUTING -s 192.168.42.0/24 -o eth1 -j MASQUERADE
[0:0] -A POSTROUTING -s 10.9.0.0/24 -o eth1 -j MASQUERADE
COMMIT
# Completed on Mon Jan 29 13:38:06 2024