Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
how do I change default gateway? manually and automatically
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
stringchopper
n00b
n00b


Joined: 07 Feb 2009
Posts: 50

PostPosted: Sun Feb 15, 2009 8:32 pm    Post subject: how do I change default gateway? manually and automatically Reply with quote

How do I change the default gateway, shown from "route"

Code:
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.16.0.0      *               255.255.0.0     U     0      0        0 eth0
loopback        *               255.0.0.0       U     0      0        0 lo
default         172.16.0.1      0.0.0.0         UG    0      0        0 eth0


When I activate my wireless with wpa_supplicant, I want to use the wireless router as the default. Wireless, on my laptop, is on a different network:

192.168.1.0/24 = wireless network
192.168.1.1 = wireless router (want this to be default only when wireless is on)

172.16.0.0/16 = wired network (I need this to access shares on the LAN, through my eth0 interface, but not for internet)
172.16.0.1 = wired router

here's my /etc/conf.d/net file
Code:

modules=( "wpa_supplicant" )
wpa_supplicant_wlan0="-Dwext"

config_eth0=( "dhcp" )

config_wlan0=( "192.168.1.92/24" )
routes_wlan0=( "default via 192.168.1.1" )


currently, I'm not sure that the "config_wlan0" lines do anything. Only eth0 comes up at boot, whether it is plugged in or not. My wireless is "on" (physical button) most of the time when I'm home, but it'd be really annoying to wait for it at boot time when I'm somewhere other than home.

Currently, every time I turn on wireless at home, I'm taking eth0 down through ifconfig to clear the routing table, then bringing wlan0 up, running wpa_supplicant, running wpa_cli and manually reassociated with wireless router, then running dhcpcd wlan0 (yes, I have to run dhcpcd to get 192.168.1.92 assigned, I suppose because it's in the pool range, yet it is a static reserved IP, assigned by mac address)

sorry for being a bit wordy! :) TIA
_________________
--
Thanks,
BP
Back to top
View user's profile Send private message
pianosaurus
l33t
l33t


Joined: 19 Apr 2004
Posts: 943
Location: Bash$

PostPosted: Sun Feb 15, 2009 11:49 pm    Post subject: Reply with quote

If you need dhcp on wlan0, then you are correct in that your config_wlan0 is useless the way it is now. I would recommend setting it to "dhcp" like you do with eth0. It shouldn't run dhcp unless it has associated with an AP, so there shouldn't be a long wait at boot time anyway. If I'm wrong, and there is, you can work around it by lowering the timeout:
Code:
config_wlan0=( "dhcp" )
dhcpcd_wlan0="-t 10"

_________________
PKA Cuber
Please add [SOLVED] to the subject of your original post when you feel that your problem is resolved.
Adopt an unanswered post
Back to top
View user's profile Send private message
pianosaurus
l33t
l33t


Joined: 19 Apr 2004
Posts: 943
Location: Bash$

PostPosted: Mon Feb 16, 2009 12:00 am    Post subject: Reply with quote

Also, you can set the default gateway manually with route add default 192.168.1.1 (edit: no you can't; see defenderBGs post below), though I don't know if there is an easy way to do this automatically. You may also have to use route del to remove the old default first, but I don't think so. I don't have the opportunity to test it at the moment.
_________________
PKA Cuber
Please add [SOLVED] to the subject of your original post when you feel that your problem is resolved.
Adopt an unanswered post


Last edited by pianosaurus on Mon Feb 16, 2009 10:13 am; edited 1 time in total
Back to top
View user's profile Send private message
defenderBG
l33t
l33t


Joined: 20 Jun 2006
Posts: 817

PostPosted: Mon Feb 16, 2009 4:33 am    Post subject: Reply with quote

The correct command would be:
route add default gw 192.168.1.1
and if you want to set a new gw, you have to delete the older one (if you had any).
The command looks like the one above, but yet you need to replace add with del.
You can find out what the default gw is with /sbin/route -n

Automaticly would be with dhcp (emerge dhcp or dhcpcd) then dhclient or dhcpcd <interface>
Back to top
View user's profile Send private message
pianosaurus
l33t
l33t


Joined: 19 Apr 2004
Posts: 943
Location: Bash$

PostPosted: Mon Feb 16, 2009 10:17 am    Post subject: Reply with quote

defenderBG wrote:
The correct command would be:
route add default gw 192.168.1.1

Oops, yes you are right. Just a typo.

defenderBG wrote:
You can find out what the default gw is with /sbin/route -n

Or just route, like he already did (see first code block of his post).

defenderBG wrote:
Automaticly would be with dhcp (emerge dhcp or dhcpcd) then dhclient or dhcpcd <interface>

His problem is that two different interfaces sets two different gateways, both through dhcp. He doesn't want the default gateway to be overridden by the wired dhcp.
_________________
PKA Cuber
Please add [SOLVED] to the subject of your original post when you feel that your problem is resolved.
Adopt an unanswered post
Back to top
View user's profile Send private message
defenderBG
l33t
l33t


Joined: 20 Jun 2006
Posts: 817

PostPosted: Mon Feb 16, 2009 1:06 pm    Post subject: Reply with quote

ok, I just read the name of the thread, your last post and answered :D
you got me here, so its 1:1.
Back to top
View user's profile Send private message
pianosaurus
l33t
l33t


Joined: 19 Apr 2004
Posts: 943
Location: Bash$

PostPosted: Mon Feb 16, 2009 2:00 pm    Post subject: Reply with quote

defenderBG wrote:
ok, I just read the name of the thread, your last post and answered :D
you got me here, so its 1:1.

:twisted: Let the games begin! :D
_________________
PKA Cuber
Please add [SOLVED] to the subject of your original post when you feel that your problem is resolved.
Adopt an unanswered post
Back to top
View user's profile Send private message
stringchopper
n00b
n00b


Joined: 07 Feb 2009
Posts: 50

PostPosted: Mon Feb 16, 2009 2:19 pm    Post subject: Reply with quote

is there a way to "dynamically" assign a metric to the default gateway that is provided to both the eth0 and wlan0 interface.... instead of adding routes and deleting them through the route command?

ie, if my laptop wired is in (at home), use that gateway as default (0.0.0.0). If and when the wireless comes up (at home, and both interfaces are active), use the gateway for wlan0 as default for internet traffic, and only use the 172.16.0.1 gateway for the traffic to the home LAN

When on the road, of course, use whatever gateway is assigned at the public Access Point as the default.

I'm pretty sure the metric option in the route command would take care of this, if "metric" here works like it does in routing protocols. But I don't want to mess with the route table every time I go out in public and have a different subnet, IP address and default gateway

EDIT: what I was trying to refer to as "metric" would more appropriately be termed "Administrative distance". The AD, in network routing tables is different depending on which protocol put the route in the table, or whether it is physically connected or statically defined. The lower AD is always chosen as the route to put into the routing table.

so what I was thinking is, "wouldn't it be great if" I could have an AD assigned to each default route... say 3 for wired at home, and 2 for wireless (making it preferred), and then use a default lower setting for any default route when in public (so it beats both my home wired and wireless, and I wouldn't have to manually delete and add routes)
_________________
--
Thanks,
BP
Back to top
View user's profile Send private message
gimpel
Advocate
Advocate


Joined: 15 Oct 2004
Posts: 2720
Location: Munich, Bavaria

PostPosted: Mon Feb 16, 2009 5:23 pm    Post subject: Reply with quote

I guess that's what networkmanager was made for.
_________________
http://proaudio.tuxfamily.org/wiki - pro-audio software overlay
Back to top
View user's profile Send private message
stringchopper
n00b
n00b


Joined: 07 Feb 2009
Posts: 50

PostPosted: Tue Feb 17, 2009 2:15 pm    Post subject: Reply with quote

gimpel wrote:
I guess that's what networkmanager was made for.


Well, I do have that emerged, but when I run the GUI, there's nothing in it, and no way to edit/add anything. I'll look into it.

At this point, if possible, I prefer to do it manually I think (if possible), so that I can learn about how these things work with linux.
_________________
--
Thanks,
BP
Back to top
View user's profile Send private message
stringchopper
n00b
n00b


Joined: 07 Feb 2009
Posts: 50

PostPosted: Tue Feb 17, 2009 3:03 pm    Post subject: Reply with quote

I've noticed that if I start the laptop without the wired cat5 cable plugged in, then bring up wlan0 (using wpa_supplicant, wpa_cli, dhcpcd), the wireless router is the default gateway listed in output of "route".

If I subsequently plug in the cat5 cable, everything works automagically for the wired network. Most importantly, the default gateway for the wired network is added to the route table with a metric (hop) of 1 instead of 0. This accomplishes what I want to do.

So now my question is, how do I ensure that eth0 stays down until wlan0 is up - or how do I ensure that wlan0 comes up first. I think, but am not sure that this takes me back to having wlan0 being set up at boot (correct). That, or leave them both down at boot, and write a script to bring them up in order.

so I recall doing something like "rc-update add net.eth0 default" when installing gentoo. I never did this for wlan0.

Should I simply do this, below, in this specific order, to bring them both up at boot, with wlan0 coming up first?

Code:
rc-update del net.eth0 default
rc-update add net.wlan0 default
rc-update add net.eth0 default


or does the order of the contents in the /etc/conf.d/net file make a difference.

cat /etc/conf.d/net (mine is presently configured with eth0 first)
Code:

modules=( "wpa_supplicant" )
wpa_supplicant_wlan0="-Dwext"

config_eth0=( "dhcp" )

config_wlan0=( "dchp" )

_________________
--
Thanks,
BP
Back to top
View user's profile Send private message
pianosaurus
l33t
l33t


Joined: 19 Apr 2004
Posts: 943
Location: Bash$

PostPosted: Tue Feb 17, 2009 8:43 pm    Post subject: Reply with quote

You could try, but I don't think it matters what order you add them to rc, since the service order is recalculated anyway. The order in /etc/conf.d/net doesn't matter, unfortunately.
_________________
PKA Cuber
Please add [SOLVED] to the subject of your original post when you feel that your problem is resolved.
Adopt an unanswered post
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6737
Location: Blighty

PostPosted: Wed Mar 21, 2018 2:53 pm    Post subject: Reply with quote

https://wiki.gentoo.org/wiki/Network_management_using_DHCPCD
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 6968

PostPosted: Wed Mar 21, 2018 3:59 pm    Post subject: Reply with quote

Doctor UberLord Jones is looking for the lost ark? :)
Back to top
View user's profile Send private message
Dominique_71
Veteran
Veteran


Joined: 17 Aug 2005
Posts: 1639
Location: Switzerland (Romandie)

PostPosted: Tue Mar 12, 2019 11:35 pm    Post subject: Reply with quote

UberLord wrote:
https://wiki.gentoo.org/wiki/Network_management_using_DHCPCD

I just added a section about routing priority in that article.
_________________
[[[ To any NSA and FBI agents reading that text: please consider ]]]
[[[ whether defending the US Constitution against all enemies, ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum