Red Hat / CentOS Linux Setting a Default Gateway

https://‮l.www‬autturi.com
Red Hat / CentOS Linux Setting a Default Gateway

To set a default gateway on a Red Hat or CentOS Linux system, you can use the route command.

The route command is used to view and modify the routing table on a Linux system. The routing table is a list of routes that the system uses to determine how to forward packets to their destination. The default gateway is the route that is used for all packets that are destined for a network that is not directly connected to the local system.

To set the default gateway on a Red Hat or CentOS system, you can use the following command:

route add default gw gateway_address

Replace gateway_address with the IP address of the default gateway.

For example, if the default gateway has an IP address of 192.168.1.1, you can use the following command:

route add default gw 192.168.1.1

This will add a default route to the routing table that points to the 192.168.1.1 gateway.

It's important to note that the route command does not persist across reboots. To make the default gateway persistent, you will need to add the route command to a startup script or configuration file that is executed at boot time.

For example, you can add the route command to the /etc/rc.d/rc.local file, which is executed at the end of the boot process.

You can also use the nmcli command to set the default gateway on a Red Hat or CentOS system. For example:

nmcli con mod "connection_name" ipv4.gateway "gateway_address"

Replace connection_name with the name of the network connection you want to modify.

Created Time:2017-10-30 14:27:14  Author:lautturi