Red socks iptables howto

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


Systems connected to the network will generally have access to the internet. In order to access 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.

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.

$ ip route show

Our default gateway line is

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

Removing default gateway is easy if we list routing table because routing table line is used withdelcommand 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 default via 192.168.122.1 dev ens3
  • ip route delis our key line which deletes specified default gateway
  • default via 192.168.122.1 dev ens3is the same as routing table

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 command like below.

$ ip route add default via 192.168.1.1 dev ens3
  • ip route addwill add provided default gateway
  • defaultmeans target network is all which is default
  • via 192.168.1.1is our default gateway network address
  • dev ens3is network interface for default gateway

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

$ ip route show default via 192.168.1.1 dev ens3 10.0.3.0/24 dev lxcbr0 proto kernel scope link src 10.0.3.1 192.168.122.0/24 dev ens3 proto kernel scope link src 192.168.122.211

 

 

Categories Blog, CCNA, CentOS, Debian, Fedora, Kali, Linux, Linux, Mint, Network, RedHat, Routing, UbuntuTags default gateway, default gateway address, define gateway, ip-tools, linux router, network, route