I have two network interfaces: LANIF interface is Ethernet with no connection to the internet, and WANIF interface is of wifi type and with outside connection. I am having some problems trying to define the default routes of both interfaces.
The ops performed to do the job are from the same script that takes the actual value of the WANIF and LANIF as args
First part: Interface forwarding and masquerading
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
# enable masquerading to allow LAN internet access
sudo iptables -F
sudo iptables -X
sudo iptables -t nat -F
# enable masquerading to allow LAN internet access
echo 'Enabling IP Masquerading and other rules...'
sudo iptables -t nat -A POSTROUTING -o "$WANIF" -j MASQUERADE
sudo iptables -A FORWARD -i "$LANIF" -o "$WANIF" -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i "$WANIF" -o "$LANIF" -j ACCEPT
This seems to do the job
Second part: Interfaces definition
# ADD NEW SUBNET TO INPUT INTERFACE
sudo sh -c "cat /etc/netplan/01-network-manager-all.yaml > /etc/netplan/01-network-manager-all.yaml.backup"
sudo sh -c "echo '
network:
version: 2
renderer: NetworkManager
ethernets:
\"$LANIF\":
addresses:
- 10.102.44.33/27
routes:
- to: default
via: 10.102.44.36
wifis:
\"$WANIF\":
addresses:
- 10.102.44.36/27
- 192.168.0.100/24
routes:
- to: default
via: 192.168.0.1
access-points:
"Network":
password: "passw"
' > /etc/netplan/01-network-manager-all.yaml"
Based on this, I would expect traffic arriving at LANIF to be routed to WANIF via 10.102.44.36. However, I am getting the following error:
Problem encountered while validating default route consistency.Please set up multiple routing tables and use `routing-policy` instead.
Error: Conflicting default route declarations for IPv4 (table: main, metric: default), first declared in LANIF but also in WANIF
The error is clear, gateway is defined in both interfaces. Executing route
and looking the network conf:
Destination Gateway Genmask Flags Metric Ref Use Iface
default _gateway 0.0.0.0 UG 600 0 0 WANIF
default _gateway 0.0.0.0 UG 20100 0 0 LANIF
Above we clearly see that both gateways exist.
WANIF
LANIF
In the screenshots the gateways seems ok, but WANIF has not internet connection.
Any help is welcomed.