Static Routes
Static routes are configured on linux servers when the enterprise has received a couple of routers, the place one router acts as a default gateway that join with the remainder of the world and inside routers join completely different branches and sections of the workplace. For a system administrator it is extremely essential to have the ability to perceive and carry out static route configurations on a linux server.
This text illustrates other ways of including and deleting static routes specifically on CentOS 7 linux system.
Verify Current Routes
Earlier than begin including or deleting static routes, it’s essential to confirm the present routes accessible, in order that any incorrect or lacking route will be rectified, added or eliminated. To take action, merely launch your terminal and situation the command beneath.
ip route present
Following command may even return comparable outcomes.
ip route checklist
Identical info may also be obtained utilizing route and netstat instructions as proven beneath
route -n
netstat -nr
Contemplate following topology, lets assume you may have a department workplace the place few shoppers want entry to the system, and the department workplace community is 172.16.1.0/16. And the default route for Server0 is about to web router IP (ie 192.168.100.1/24). Right here Its inconceivable to achieve department workplace by way of web router.
You’ll create a static route on the server which can let the server know, that for reaching 172.16.1.0/16 subnet it should handover the visitors to 192.168.100.99. This will probably be achieved by configuring a static route.
First verify interface ID or quantity on which two routers are accessible, by issuing ifconfig command. It’s enp0s3 in my case.
Add a Non permanent Static Route
ip route add 172.16.0.0/16 through 192.168.100.99 dev enp0s3
Delete a Non permanent Static Route
The static route added utilizing above technique stays configured until the system is working, it is going to be eliminated if the system is rebooted due to this fact it’s known as non permanent static route.
Now, if the the static route isn’t any extra wanted or the non permanent static was beforehand misconfigured and must be eliminated, then you’ll have to delete the route utilizing following command:
ip route delete 172.16.0.0/16 through 192.168.100.99 dev enp0s3
Add a Everlasting or Persistent Static Route
It may be skilled that non permanent static routes aren’t persistent; these routes are deleted upon subsequent reboot, now we’ll see find out how to make them everlasting or persistent.
We must create a file the place interface configuration recordsdata reside (ie /and so on/sysconfig/network-scripts)
Problem following command to create a brand new file named route-enp0s3 and kind the community and the gateway IP from which visitors must be handed adopted by interface ID or title as proven beneath.
vi /and so on/sysconfig/network-scripts/route-enp0s3
Sort the static route as per following sample.
172.16.0.0/16 through 192.168.100.99 dev enp0s3
- Save the file
- Restart community service
- View routing desk
Delete a Everlasting or Persistent Static Route
- Take away the file named route-enp0s3
- Restart community service
- View routing desk
rm -rf /and so on/sysconfig/network-scripts/route-enp0s3
systemctl restart community
ip route present
Loved the content material! Please discover extra.