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 dev ens3
  • defaultmeans this line is the default gateway
  • via 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 dev ens3
  • ip route delis our key line which deletes specified default gateway
  • default via 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 dev ens3
  • ip route addwill add provided default gateway
  • defaultmeans target network is all which is default
  • via 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 dev ens3 dev lxcbr0 proto kernel scope link src dev ens3 proto kernel scope link src



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