Static Routing Configuration
Ubuntu 18.04 and Later (Netplan)
Configuration File: /etc/netplan/*.yaml
network:
version: 2
ethernets:
eth0:
dhcp4: false
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
routes:
- to: 10.0.0.0/8
via: 192.168.1.254
Apply Configuration
# Test configuration
netplan try
# Apply configuration
netplan apply
Ubuntu 16.04 and Earlier (interfaces)
Configuration File: /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
# Add static route
up route add -net 10.0.0.0/8 gw 192.168.1.254
down route del -net 10.0.0.0/8 gw 192.168.1.254
Apply Configuration
systemctl restart networking
CentOS/RHEL
Using NetworkManager
# Check connections
nmcli con show
# Configure IP
nmcli con mod eth0 ipv4.addresses 192.168.1.100/24
nmcli con mod eth0 ipv4.gateway 192.168.1.1
nmcli con mod eth0 ipv4.dns 8.8.8.8
nmcli con mod eth0 ipv4.method manual
# Add static route
nmcli con mod eth0 +ipv4.routes "10.0.0.0/8 192.168.1.254"
# Apply configuration
nmcli con up eth0
Verify Routing
# Check routing table
ip route show
route -n
# Test connectivity
ping destination_IP
traceroute destination_IP