- How to set the Default gateway
- You must log in to answer this question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- How can I find the default gateway of a machine?
- How to Add or Change the Default Gateway in Linux
- Using the Terminal
- Editing Your Configuration File
- Community Q&A
- Tips
- You Might Also Like
How to set the Default gateway
You can use route like in route add default gw 192.168.0.254 for example.
And if route is not present, but ip is, you can use it like this: ip route add default via 192.168.0.254 dev eth0 , assuming that 192.168.0.254 is the ip of your gateway
ifconfig is deprecated on Linux and furthermore, it’s the wrong tool for the job. To set the default gateway on Linux use the ip command as follows:
ip route add default via dev # e.g. ip route add default via 192.168.0.101 dev eth0
For remove gateway in Linux Command : route delete default gw 192.168.1.1 eth1
For add gateway in Linux Command : route add default gw 192.168.1.250 eth1
example: route add default gw 192.168.1.2 eth0
OR use hostname such as dsl-router:
route add default gw dsl-router eth0
Or use the ip command (newer syntax) to route all traffic via 192.168.1.254 gateway connected via eth0 network interface for example:
ip route add 192.168.1.0/24 dev eth0
ip route add 192.168.1.0/24 via 192.168.1.254
You must log in to answer this question.
Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533
Linux is a registered trademark of Linus Torvalds. UNIX is a registered trademark of The Open Group.
This site is not affiliated with Linus Torvalds or The Open Group in any way.
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
How can I find the default gateway of a machine?
I’m trying to find the default Gateway of a machine, but I see multiple interfaces. Also, when I find my IP address from the below website, it gives me a different IP address. I thought the default Gateway and external IP would be the same? Correct me if I’m wrong.
https://www.privateinternetaccess.com/pages/whats-my-ip/
Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0 10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 10.2.0.0 192.168.255.9 255.255.255.0 UG 0 0 0 tun0 192.168.33.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 192.168.255.1 192.168.255.9 255.255.255.255 UGH 0 0 0 tun0 192.168.255.5 0.0.0.0 255.255.255.255 UH 0 0 0 tun4 192.168.255.5 0.0.0.0 255.255.255.255 UH 0 0 0 tun6 192.168.255.5 0.0.0.0 255.255.255.255 UH 0 0 0 tun5 192.168.255.5 0.0.0.0 255.255.255.255 UH 0 0 0 tun2 192.168.255.9 0.0.0.0 255.255.255.255 UH 0 0 0 tun0 192.168.255.13 0.0.0.0 255.255.255.255 UH 0 0 0 tun3 192.168.255.13 0.0.0.0 255.255.255.255 UH 0 0 0 tun1
$ netstat -r Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface default 10.0.2.2 0.0.0.0 UG 0 0 0 eth0 10.0.2.0 * 255.255.255.0 U 0 0 0 eth0 10.2.0.0 192.168.255.5 255.255.255.0 UG 0 0 0 tun6 192.168.33.0 * 255.255.255.0 U 0 0 0 eth1 192.168.255.1 192.168.255.5 255.255.255.255 UGH 0 0 0 tun6 192.168.255.5 * 255.255.255.255 UH 0 0 0 tun6 192.168.255.5 * 255.255.255.255 UH 0 0 0 tun3 192.168.255.5 * 255.255.255.255 UH 0 0 0 tun2 192.168.255.5 * 255.255.255.255 UH 0 0 0 tun4 192.168.255.9 * 255.255.255.255 UH 0 0 0 tun5 192.168.255.13 * 255.255.255.255 UH 0 0 0 tun0 192.168.255.13 * 255.255.255.255 UH 0 0 0 tun1
How to Add or Change the Default Gateway in Linux
wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 14 people, some anonymous, worked to edit and improve it over time.
This article has been viewed 1,011,156 times.
If you need to find or change the IP address of your default gateway or router on Linux, you’re in luck—it’s super easy to do. This wikiHow article will show you how to use the route command to find the default gateway IP address on Linux, and how to set a new default gateway in your /etc/network/interfaces configuration file.
Using the Terminal
Open the Terminal. You can open the Terminal from the side bar, or by pressing Ctrl + Alt + T . [1] X Research source
View your current default gateway. You can check what your default gateway is set to by typing route and pressing ↵ Enter . The address next to «default» shows your default gateway, and the interface it is assigned to is displayed on the right side of the table.
- Type sudo route delete default gw IP Address Adapter . For example, to delete the default gateway 10.0.2.2 on the eth0 adapter, type sudo route delete default gw 10.0.2.2 eth0 .
Type . sudo route add default gw IP Address Adapter . For example, to change the default gateway of the eth0 adapter to 192.168.1.254, you would type sudo route add default gw 192.168.1.254 eth0 . [3] X Research source You’ll be prompted for your user password in order to complete the command.
Editing Your Configuration File
Open the configuration file in an editor. Type sudo nano /etc/network/interfaces to open the file in the nano editor. Editing your configuration file will keep your changes every time the system restarts. [4] X Research source
Navigate to the correct section. Find the section for the adapter you want to change the default gateway for. For a wired connection, this is usually eth0 .
Add . gateway IP Address to the section. For example, type gateway 192.168.1.254 to make the default gateway 192.168.1.254. [5] X Research source
Restart your network. Restart your network by typing sudo /etc/init.d/networking restart . [6] X Research source
Community Q&A
Thanks! We’re glad this was helpful.
Thank you for your feedback.
As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow
Tips
You Might Also Like
A Complete Guide to Managing an iPod in Linux
Can Linux Run .exe Files? How to Run Windows Software on Linux
How to Open Linux Firewall Ports: Ubuntu, Debian, & More
How to Run an INSTALL.sh Script on Linux in 4 Easy Steps
Use Ping in Linux: Tutorial, Examples, & Interpreting Results
How to Delete Read-Only Files in Linux
How to Install Linux on Your Computer