1

I am trying to connect one of my PCs to the Internet via a WiFi network using a notebook. Here is my network :

(Wifi) <=============> (Notebook) <===============> (Desktop)
       (192.168.1.x)                 (10.12.0.x)
                      (192.168.1.85                 (10.12.0.2)
                      & 10.12.0.1)

So, I have ipv4_forward enabled on my netbook, and this NAT rule :

iptables -t nat -A POSTROUTING -s 10.12.0.0/24 -j MASQUERADE

Here is my routing table on my notebook :

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.254   0.0.0.0         UG    0      0        0 wlan0
10.0.0.0        0.0.0.0         255.0.0.0       U     0      0        0 eth0
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
192.168.1.0     0.0.0.0         255.255.255.0   U     9      0        0 wlan0
192.168.1.85    127.0.0.1       255.255.255.255 UGH   303    0        0 lo

Here is my routing table on my desktop :

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.12.0.0       0.0.0.0         255.255.255.0   U     0      0        0 enp2s0
192.168.1.0     10.12.0.1       255.255.255.0   UG    0      0        0 enp2s0

I can ping everything on the 192.168.1.x network (my Internet gateway 192.168.1.254 included), but I can't add the simple route

route add default gw 192.168.1.254 enp2s0

or

ip route add default via 192.168.1.254 dev enp2s0

I keep getting errors like :

SIOCADDRT: Network is unreachable
RTNETLINK answers: Network is unreachable

And, of course, I can't ping any WAN server from my desktop. Do you have an idea of what I am doing wrong ?

Thank you.

10
  • 1
    I think what you are really looking for is ip route add default via 10.12.0.1 dev enp2s0.
    – Glueon
    Oct 15, 2014 at 20:34
  • @Glueon - Make that an answer and I'll upvote it. Oct 15, 2014 at 20:44
  • 2
    @MayeuIC - You're getting the Network is unreachable errors because the desktop machine has no route to 192.168.1.254 via any entry in the routing table. You want the desktop computer's default gateway to be the 10.12.0.1 NIC in the netbook because the desktop can reach 10.12.0.1. Oct 15, 2014 at 20:46
  • 1
    Thank you to both of you. May I ask you why I don't need to specify the gateway (192.168.1.254) ? is it because the netbook already knows it and forwards the packets to it, thus using its own routing table to forward the packets to the right destination ? (Sorry, I am not so familiar with routing)
    – MayeulC
    Oct 15, 2014 at 20:50
  • 1
    @MayeulC Because your dekstop computer is not connected to 192.168.1.254 (you are not part of the 192.168.1.0/24 network). You need a routing hop to reach it, so your gateway must be what's handling this hop on the network you are connected in : your notebook. That's routing. Oct 15, 2014 at 21:05

1 Answer 1

1

I think what you are really looking for is: ip route add default via 10.12.0.1 dev enp2s0

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