How To Add or Change Default Route or Default Gateway in Ubuntu, Linux? – POFTUT

How To Add or Change Default Route or Default Gateway in Ubuntu, Linux?

Systems connected to the network will generally access to the internet. In order to access to the internet they need some network configuration like gateway or default gateway. In this tutorial we will examine how to add or change default gateway in Ubuntu, Debian, CentOS, Fedora, Mint, Kali operating systems.

List Routing Table

Routing table is used to route IP network communication. Hosts generally uses default route to send packages which will redirect them accordingly to transmit destination. We will start by listing current routing table. We will use ip route show command like below.

List Routing Table

List Routing Table

Our default gateway line is

  • default means this line is default gateway
  • via 192.168.122.1 specifies next hop which is default gateway IP address
  • dev ens3 is the interface we want use to access default gateway

Remove Existing Default Gateway

Removing default gateway is easy if we list routing table because routing table line is used with del command like below. But keep in mind if you are connecting system remotely from different network which means if you are using default route you connection will be lost.

  • ip route del is our key line which deletes specified default gateway
  • default via 192.168.122.1 dev ens3 is the same as routing table

Add New Default Gateway

As stated previously default gateway is used to send packages in order to transmit to the destination. We can add new default gateway with the ip route add command like below.

LEARN MORE  What Is System Administrator and Duties ?

  • ip route add will add provided default gateway
  • default means target network is all which is default
  • via 192.168.1.1 is our default gateway network address
  • dev ens3 is network interface for default gateway

Check

List routing table again and ping some of remote networks will give the status of default gateway

 

How To Add or Change Default Route or Default Gateway in Ubuntu, Linux? Infografic

How To Add or Change Default Route or Default Gateway in Ubuntu, Linux? Infografic

How To Add or Change Default Route or Default Gateway in Ubuntu, Linux? Infografic

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)