Static routing problem

Hello,

I have problem during the static routing configuration. I have two networks in virtualbox (192.168.57.0/224 and 192.168.58.0/24), I have configured static routes on both, host in network 57 and host in network 58 but when I try to ping each other it doesnt work. My network looks like this one:

Routing table on CentOS host:

[armin@udemy-lfcs ~]$ sudo netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.57.0    0.0.0.0         255.255.255.0   U         0 0          0 enp0s3
192.168.58.0    192.168.57.1    255.255.255.0   UG        0 0          0 enp0s3
192.168.122.0   0.0.0.0         255.255.255.0   U         0 0          0 virbr0
[armin@udemy-lfcs ~]$ sudo ip route
192.168.57.0/24 dev enp0s3 proto kernel scope link src 192.168.57.3 
192.168.58.0/24 via 192.168.57.1 dev enp0s3 
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown 

Routing table on Ubuntu host:

armin@lfcs-ubuntu:~$ sudo netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.57.0    192.168.58.1    255.255.255.0   UG        0 0          0 enp0s3
192.168.58.0    0.0.0.0         255.255.255.0   U         0 0          0 enp0s3
armin@lfcs-ubuntu:~$ sudo ip route
192.168.57.0/24 via 192.168.58.1 dev enp0s3 
192.168.58.0/24 dev enp0s3 proto kernel scope link src 192.168.58.3 

Routing table on my router which is Ubuntu VM:

armin@lfcs-ubuntu-R1:~$ sudo netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         10.0.2.2        0.0.0.0         UG        0 0          0 enp0s3
10.0.2.0        0.0.0.0         255.255.255.0   U         0 0          0 enp0s3
10.0.2.2        0.0.0.0         255.255.255.255 UH        0 0          0 enp0s3
10.0.2.3        0.0.0.0         255.255.255.255 UH        0 0          0 enp0s3
192.168.57.0    0.0.0.0         255.255.255.0   U         0 0          0 enp0s8
192.168.58.0    0.0.0.0         255.255.255.0   U         0 0          0 enp0s9

armin@lfcs-ubuntu-R1:~$ sudo ip route
default via 10.0.2.2 dev enp0s3 proto dhcp src 10.0.2.15 metric 100 
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15 metric 100 
10.0.2.2 dev enp0s3 proto dhcp scope link src 10.0.2.15 metric 100 
10.0.2.3 dev enp0s3 proto dhcp scope link src 10.0.2.15 metric 100 
192.168.57.0/24 dev enp0s8 proto kernel scope link src 192.168.57.1 
192.168.58.0/24 dev enp0s9 proto kernel scope link src 192.168.58.1

For example, I’am able to ping 192.168.57.1 from my Ubuntu host and 192.168.58.1 from my CentOS host, but I can’t ping 192.168.57.3 from my Ubuntu host and 192.168.58.3 from my CentOS host.

Can anyone help me to understand where is the problem ?

Have you enabled IP forwarding on the Router VM?

1 Like

@al1 no, I haven’t. I don’t know how to enable it. Could you explain me please ?

Is it mean I have to create ip tables rule ?

You can check this with sysctl net.ipv4.ip_forward . To enable it, set net.ipv4.ip_forward=1 in /etc/sysctl.conf and then run sysctl -p to apply the changes.

Also if you want to play around with routers you might be interested in pfSense/OPNsense.

1 Like

Dear @al1 , it works now. I did as you said and ping works now:

armin@lfcs-ubuntu-R1:/etc/netplan$ cat /etc/sysctl.conf  | egrep -v "^#|^$"
armin@lfcs-ubuntu-R1:/etc/netplan$ sudo vi /etc/sysctl.conf 
armin@lfcs-ubuntu-R1:/etc/netplan$ cat /etc/sysctl.conf  | egrep -v "^#|^$"
net.ipv4.ip_forward=1
armin@lfcs-ubuntu-R1:/etc/netplan$ sudo sysctl -p
net.ipv4.ip_forward = 1
[armin@lfcs-centos ~]$ ip -c a s enp0s3
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:2a:1e:a5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.57.3/24 scope global enp0s3
       valid_lft forever preferred_lft forever
[armin@lfcs-centos ~]$ ping -c 5 192.168.58.3
PING 192.168.58.3 (192.168.58.3) 56(84) bytes of data.
64 bytes from 192.168.58.3: icmp_seq=1 ttl=63 time=1.92 ms
64 bytes from 192.168.58.3: icmp_seq=2 ttl=63 time=2.24 ms
64 bytes from 192.168.58.3: icmp_seq=3 ttl=63 time=2.24 ms
64 bytes from 192.168.58.3: icmp_seq=4 ttl=63 time=2.30 ms
64 bytes from 192.168.58.3: icmp_seq=5 ttl=63 time=2.30 ms

--- 192.168.58.3 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4032ms
rtt min/avg/max/mdev = 1.922/2.201/2.302/0.145 ms

I’m interested in routing so I gonna try to learn about pfSense/OPNsense.

Thank you @al1 .