Debian / Ubuntu Linux Setting a Default Gateway

w‮‬ww.lautturi.com
Debian / Ubuntu Linux Setting a Default Gateway

To set a default gateway on a Debian or Ubuntu Linux system, you can use the route command.

  1. Determine the name of the network interface that you want to set the default gateway for. You can use the ip a command to list all the network interfaces:
ip a

The output will list the names of the network interfaces, along with their status and IP address information.

  1. Use the route command to add the default gateway:
sudo route add default gw GATEWAY_IP_ADDRESS DEVICE_NAME

Replace GATEWAY_IP_ADDRESS with the IP address of the default gateway and DEVICE_NAME with the name of the network interface that you want to set the default gateway for.

For example, to set the default gateway to 192.168.1.1 for the eth0 interface, you would run:

sudo route add default gw 192.168.1.1 eth0
  1. To make the default gateway persistent across reboots, you can add a line to the /etc/network/interfaces file. For example, to set the default gateway for the eth0 interface:
auto eth0
iface eth0 inet static
        address 192.168.1.100
        netmask 255.255.255.0
        gateway 192.168.1.1

Save the file and exit. The default gateway will now be set automatically on boot.

Created Time:2017-10-28 14:02:26  Author:lautturi