[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Where did my gateway go?



Lee wrote:

> If I had something like 10.10.11.0/24 connected to the wireless router
> I can see adding a static route so the laptop goes directly to the
> wlan default gateway instead of the ethernet default gateway (+ maybe
> getting a redirect) & then to the wlan router to the destination.
> 
> But other than that.. I'm missing why you think it'd be better to
> specify exactly what goes where.

So to be precise there is only one default GW, be it by entry or as you said
determinded by the metrics. There is only one.

What I do is to specify which interface is specific to which network. This
way the computer knows where to route those packets.

For example I have 

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use
Iface
0.0.0.0         192.168.40.1    0.0.0.0         UG    100    0        0
enp0s25
192.168.40.0    0.0.0.0         255.255.255.0   U     100    0        0
enp0s25

The we add another interface enp0s29u1u6 (which is created automatically
after plugin for example mobile phone/rndis) and assigns IP 192.168.2.11 to
it
The I add a route for this network for this interface

ip route add 192.168.2.15/32 via 192.168.2.11 dev enp0s29u1u6 

and few iptables rules to enable routing in both directions

        echo 1 > /proc/sys/net/ipv4/ip_forward
        iptables -P FORWARD ACCEPT
        iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.2.0/24
        iptables -I INPUT 1 -s 192.168.2.15 -j ACCEPT

Now we have following routing table

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use
Iface
0.0.0.0         192.168.40.1    0.0.0.0         UG    100    0        0
enp0s25
192.168.2.0     0.0.0.0         255.255.255.0   U     100    0        0
enp0s29u1u6
192.168.2.15    192.168.2.11    255.255.255.255 UGH   0      0        0
enp0s29u1u6
192.168.40.0    0.0.0.0         255.255.255.0   U     100    0        0
enp0s25

as you see the network 192.168.2.0 is routed via enp0s29u1u6. Because I have
only one host behind I do not specify the whole network, but just this IP.

This way your machine works as a route and it works despite the metrics. If
you use the metrics it does try routing packets from network with higher
metrics through network with lower metrics first and after this tries the
correct one.
The configuration I use ensures each network/interface routes the traffic
destined for the network it is responsible for.

On the device itself it is similar situation. There is one wired and one
wireless networks. The wireless network is the default GW.

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use
Iface
0.0.0.0         10.0.0.138      0.0.0.0         UG    0      0        0
wlan0
10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0
wlan0
10.0.0.138      0.0.0.0         255.255.255.255 UH    0      0        0
wlan0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0
rndis0

The outgoing traffic is using the wireless interface with GW 10.0.0.138.
Only the packets from the wired network are routed back to the wired
network.

I can not add another default GW as entry already exists, but I can add a GW
with higher metrics

# ip route add default via 192.168.2.11
RTNETLINK answers: File exists

# ip route add via 192.168.2.11 metric 101

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use
Iface
0.0.0.0         10.0.0.138      0.0.0.0         UG    0      0        0
wlan0
0.0.0.0         192.168.2.11    0.0.0.0         UG    101    0        0
rndis0
10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0
wlan0
10.0.0.138      0.0.0.0         255.255.255.255 UH    0      0        0
wlan0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0
rndis0

So this is why I am asking how it is possible to have two entries with same
metrics for the gateway.

As I am not an expert, I would like to know how it is possible.

regards


Reply to: