linux_wiki:route_ip_traffic_and_create_static_routes

This is an old revision of the document!


Route IP Traffic And Create Static Routes

General Information

Routing IP traffic and creating static routes.


Lab Setup

The following virtual machines will be used:

  • server1.example.com (192.168.1.150) → Configure the routes here

Linux Routing

Ensure IP Forwarding is enabled if using router like functionality

# Temp Immediate Change
echo 1 > /proc/sys/net/ipv4/ip_forward
 
# Persistent Change that takes place upon system boot
vim /etc/sysctl.d/overrides.conf
 
net.ipv4.ip_forward = 1


Show Route Table

ip route show


Create static route (NOT persistent)

ip route add 216.58.217.0/24 via 192.168.1.254 dev eth1
  • 216.58.217.0/24 → destination network
  • via 192.168.1.254 → use this gateway
  • dev eth1 → use this interface


Remove static route

ip route delete 216.58.217.0/24 via 192.168.1.254 dev eth1


Creating a persistent static route.


Create config file

vim /etc/sysconfig/static-routes
 
any net 216.58.217.0/24 gw 192.168.1.254 dev eth0
  • any net → source from any network
  • 216.58.217.0/24 → traffic to this destination
  • gw 192.168.1.254 → use this gateway
  • OPTIONAL: dev eth0 → use this device


Restart the network service

systemctl restart network


View route

ip route show

  • Open nmtui
    nmtui
  • Enter on “Edit a connection”
  • Select the target network interface to use, press Enter.
    • Scroll down to “Routing”, Enter on “<Edit…>”
    • Enter on “<Add…>”
      • Type the Destination/Prefix
      • Next Hop
      • Optional Metric (default static is 0)
    • Tab to <OK> and press 'Enter'
  • Scroll to the bottom and Enter on “<OK>”
  • Tab over to <QUIT>
  • File is created at: /etc/sysconfig/network-scripts/route-<ifname>
  • Restart the network service
    systemctl restart network
  • View route
    ip route show

  • linux_wiki/route_ip_traffic_and_create_static_routes.1476129509.txt.gz
  • Last modified: 2019/05/25 23:50
  • (external edit)