NOTE: If client devices (
computer B
in this example) want to obtain internet through the gateway computer, maybe they still need to configure nameserver resolution. This is not explained here (a gateway does not necessarily serve internet).
I am trying to understand the fundamentals of networks routing.
So I am experimenting with my LAN (I don't need internet for now, just LAN communications).
I know the network configuration matters are a rather complex thing, but I am just trying to make a computer (say A) to act as a gateway for another (say B) (both running Ubuntu Linux).
I only need B to be capable to reach the router, that is only reachable for A.
This is the case:
Router for computer A --> 192.168.0.1
Computer A - eth0 --> 192.168.0.2
Computer A - eth1 --> 192.168.1.1
Computer B - eth0 --> 192.168.1.2
Computer A connects fine to router.
Computer A and B connect fine (ping, SSH... etc) between them.
Computer B can not reach the router for computer A.
I was thinking that just adding on B Computer A as default gateway and activating IP Forwarding on A would make B to be able to reach the router for A:
luis@ComputerB:~$ sudo route add default gw 192.168.1.1
luis@ComputerB:~$ sudo routel
target gateway source proto scope dev tbl
127.0.0.0 broadcast 127.0.0.1 kernel link lo local
127.0.0.0 8 local 127.0.0.1 kernel host lo local
127.0.0.1 local 127.0.0.1 kernel host lo local
127.255.255.255 broadcast 127.0.0.1 kernel link lo local
192.168.1.0 broadcast 192.168.1.2 kernel link eth0 local
192.168.1.2 local 192.168.1.2 kernel host eth0 local
192.168.1.255 broadcast 192.168.1.2 kernel link eth0 local
default 192.168.1.1 eth0
169.254.0.0 16 link eth0
192.168.1.0 24 192.168.1.2 kernel link eth0
And on Computer A (the intermediate gateway):
root@ComputerA:~$ echo 1 > /proc/sys/net/ipv4/ip_forward
Computer B can still ping computer A, but router for A does not answer:
luis@ComputerB:~$ ping 192.168.0.1
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
^C
(No ping response)
Is this the correct procedure to make a computer running Linux to act as a gateway for another computer in a simple manner?