• Home
  • About Us
  • Contact
  • Privacy Policy

LinuxAdmin.io

  • Home
  • Tutorials
    • System Administration
    • Linux Tutorials
    • Web Hosting
    • WordPress
    • Virtualization
    • Troubleshooting
    • OpenStack

How To Configure A Default Gateway on CentOS

Default Gateway

A default gateway is what linux will use to interact with other computers connected on the network. This is typically the router and will send all packets to that IP address. The actions below all use the route command, to find out more possiblities view the route man page.

View the Current Routing Table

To view the current routing table on a linux server you can do the following:

route -n

Which will return the following output:
# route -n 
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 100 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0

You can see that the default route is the first line sending all packets to the 192.168.1.1 Gateway.

Remove A Default Gateway

To remove a default route you will need to use the following command, substituting 192.168.1.1 with the IP address of the default route you previously saw

# route del default gw 192.168.1.1

Once you have removed it confirm by doing another route -n

# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0

Add A Default Gateway

To add a new default route you will need to use the following:

route add default gw 192.168.1.1

Once you have added the new route you will see it appear in the routing table:

# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 100 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0

Permanently Configure The Default Gateway

To make the new default gateway persist through a reboot, you will need to edit the network interface file:

nano /etc/sysconfig/network-scripts/ifcfg-eth0

Substitute the name of the file with the interface you are setting the route for.

Update or append the following line the file switching out 192.168.1.1 with the IP address of the default router:

GATEWAY=192.168.1.1

Once you have saved the file, you can restart networking to ensure it is working properly

/etc/init.d/networking restart
Jul 5, 2017LinuxAdmin.io
3.3 6 votes
Article Rating
How To Setup SSH Key AuthenticationHow To Upgrade Supervisord In CentOS 6
You Might Also Like
 
FirewallD Introduction On CentOS 7
 
Bridged Networking Setup For KVM Virtualization
Subscribe
Notify of
guest

guest

0 Comments
Inline Feedbacks
View all comments
7 years ago Linux System Administration networking76,120
Recent Posts
  • Configuring Firewalld to Work Seamlessly with Docker on CentOS
  • Mastering NGINX Tuning: Optimizing Web Server Performance
  • Exploring eBPF: Revolutionizing Network and System Monitoring
  • Kubernetes: Installation and Overview on CentOS 8
  • Install Docker on Centos 8
Most Commented
Hot Clone Linux Server with Rsync
Hot Clone A CentOS Server With Rsync
14 Comments
ngx_cache_purge module
Install The ngx_cache_purge Module In Nginx
8 Comments
piwik-nginx
Piwik Analytics on Nginx
8 Comments
Tags
linuxcentosLinux Performance Tuningsysadminkvmnetworkingmemcachedanalyticssystemd
About

We love Linux and are dedicated to creating Linux administration tutorials for System Administrators since 2016.

Most Viewed
Default Gateway
How To Configure A Default Gateway on CentOS
76,120 views
Zend Opcache
Setup and Optimize Zend OpCache
47,105 views
Install ffmpeg
FFMpeg Install On CentOS 7
21,672 views
Archives
Email subscription

Sign up for our newsletter to receive the latest news and event postings.

2018 © LinuxAdmin.io
wpDiscuz