Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Image RemovedImage Added

https://devconnected.com/how-to-add-route-on-linux/#Using_etcnetworkinterfaces



Centos

create a "route" file:

vi /etc/sysconfig/network-scripts/route-eno16777736

default via 192.168.26.2



[root@centos7 network-scripts]# systemctl restart network.service

[root@centos7 network-scripts]# ip route

default via 192.168.26.2 dev eno16777736

169.254.0.0/16 dev eno16777736  scope link  metric 1002

192.168.26.0/24 dev eno16777736  proto kernel  scope link  src 192.168.26.11

Ubuntu
create this file

/etc/network/interfaces

static ip address


Code Block
titlestatic ip@ and static route
auto eth0
iface eth0 inet static
      address 10.0.2.2
      netmask 255.255.255.0
      up route add -net 10.0.3.0 netmask 255.255.0.0 gw 10.0.2.1


dynamic ip address


Code Block
titledynamic IP@ and static route
auto eth0
iface eth0 inet dhcp
      up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.0.10.4


show routesroot@boxed:~# ip r
default via 192.168.0.1 dev wlan0
172.32.0.0/16 via 192.168.116.1 dev eth0
192.168.0.0/24 dev wlan0 proto kernel scope link src 192.168.0.146
. . . 
to be ch3eck firstip route add -net 172.32.0.0 netmask 255.255.0.0 gw 192.168.116.1