How to add or change default gateway on Linux

Author: Louise Ward
Date Of Creation: 8 February 2021
Update Date: 1 July 2024
Anonim
Change the default gateway in linux
Video: Change the default gateway in linux

Content

The default gateway is the IP address of the router. Usually the port is automatically discovered by the operating system through the installation process, but you may need to change it, especially if your computer has multiple adapters or routers on the network. .

Steps

Part 1 of 2: Using Terminal

  1. Open the Terminal app. You can open Terminal from the sidebar, or click Ctrl+Alt+T.

  2. View the current default gateway. You can check which default gateway is installed by typing route then press ↵ Enter. The address next to the word "default" is your default gateway and the interface to which it is assigned will appear on the right side of the table.

  3. Delete the current default gateway. If the computer has more than one default connection set up, a connection conflict may occur. If you want to change the current IP address of your router, you should delete it first.
    • Enter an order sudo route delete default gw IP AddressAdapter. For example, to delete the default 10.0.2.2 connection port on your router, type sudo route delete default gw 10.0.2.2 eth0.

  4. Enter an order.sudo route add default gw IP AddressAdapter. For example, if you want to change the IP address of your router to 192.168.1.254, type sudo route add default gw 192.168.1.254 eth0. You will be asked to enter your user password to complete the command. advertisement

Part 2 of 2: Editing configuration files

  1. Open the configuration file with an editor. Type commands sudo nano / etc / network / interfaces to open the file in the Nano software. Editing the system file will preserve your changes every time the computer restarts.
  2. Navigate to the appropriate section. Find the section about the router for which you want to change the IP address. For a wired connection, a router is usually.
  3. More .gateway IP Address into this section. For example, type gateway 192.168.1.254 to set the default gateway to 192.168.1.254.
  4. Save your changes and exit. Press Ctrl+X then press the key Y to save changes and exit.
  5. Reboot the network. Reboot your network by typing the command sudo /etc/init.d/networking restart. advertisement