Adding static route on Ubuntu router

Adding static route

sudo route add -net 192.168.5.0 netmask 255.255.255.0 gw 192.168.1.254

To remove static route

route
sudo route del -net 192.168.5.0 netmask 255.255.255.0 gw 192.168.1.254

Network: 192.168.5.0/24
Gateway: 192.168.1.254 (anoter router hosting new network 192.168.5.0/24)
Netmask: 255.255.255.0

 

To make it permanent,

sudo nano /etc/network/interfaces
# WAN interface
auto eth1
iface eth1 inet static
address 202.xx.xx.xx
gateway 202.xx.xx.xx
netmask 255.255.255.240
dns-nameservers 8.8.8.8

# LAN interface
auto eth0
iface eth0 inet static
address 192.168.1.240
netmask 255.255.255.0
post-up route add -net 192.168.5.0 netmask 255.255.255.0 gw 192.168.1.254 

post-up route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.254

Verify by checking the route

route 
ip route
netstat -rn

Verify your IP and DNS server

hostname -I
hostname -d

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top