CentOS Change Gateway: Step-by-Step Guide
To modify the gateway of a CentOS server, you can follow these steps:
- Open the terminal window and log in as root user.
- Open the network configuration file “/etc/sysconfig/network” using a text editor such as vi or nano.
vi /etc/sysconfig/network
- Locate and edit the following lines in the file, and change the “GATEWAY” address to the new gateway address you want to set.
GATEWAY=新网关地址
- Save and close the file.
- Edit the network configuration file “/etc/sysconfig/network-scripts/ifcfg-eth0” (if you are using an Ethernet connection, replace “eth0” with the appropriate interface name for other interfaces).
vi /etc/sysconfig/network-scripts/ifcfg-eth0
- Find and edit the following lines in the file, changing the “GATEWAY” address to the new gateway address you want to set.
GATEWAY=新网关地址
- Save and close the file.
- Restart the network service for the changes to take effect.
service network restart
- Ensure that your server can successfully connect to the new gateway address by checking the connection using the ping command.
ping 新网关地址
After completing the above steps, the gateway settings of your CentOS server will be successfully changed.