[Last Call] Learn how to a build a cloud-first strategyRegister Now


Login or Boot up Command

Posted on 2003-11-29
Medium Priority
Last Modified: 2012-05-04
I am using SuSe Linux 9.0.

For whatever reason I have to set my default gateway by executing, as root, the command

ip route add default via dev wlan0

Question is, where is the best place to put this command so that it gets executed on boot, or, perhaps better, on logon for any user.  Remember, especially on logon for any user, the command must be executed as root.

If more than the command itself has to be added, please include the extra stuff (like switching to root and back).
Question by:robertjbarker
  • 4
  • 3
  • 2
  • +1

Author Comment

ID: 9843938
And if anybody knows how to execute the command on wireless lan (PCMCIA) card insert, that would be even better.
LVL 24

Assisted Solution

shivsa earned 500 total points
ID: 9843949
add these to your /etc/inittab.

startup scripts live in /etc/rc.d/init.d, and are activiated by the presence or absence of a symbolic link to that location in /etc/rc.d/rc3.d

man inittab.

when user login then u can put this command to shell profile file.
like if user has cshell put in .cshrc
ksh then in .profile
sh:     .login
bash:     .bshrc

u have to enable sudo program so that user can run command as a root.
sudo ip route add default via dev wlan0

LVL 51

Accepted Solution

ahoffmann earned 500 total points
ID: 9846359
echo 'default wlan0' >>/etc/sysconfig/network/routes

There should be a way to configure it in yast/yast2 too ...
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 9848672
What seems to have worked is putting the single line

       ip route add default via dev wlan0

in a script in directory "/etc/sysconfig/network/if-up.d".  I chose "wlan0-up" as the name of the script, but I am pretty sure it does not matter what the name of the script is.  I got this idea from reading the file "/etc/sysconfig/network/config" which says that a script in that directory will be executed when an interface comes up.  I suppose that means it will be executed when eth0 comes up also - pretty sure that will not make a difference though.

I wish I knew how to get DHCP working completely with wlan0.  eth0 works fine with the same DHCP server, my wireless router (which includes a few wired ports).  And wlan0 can get an IP, but nothing else.

So, I fill in the domain name servers in the YAST2 network card configuration dialog.  And those take.
I also tried filling in the default gateway and/or a specific default route in the same place.  The route file, /etc/sysconfig/network/routes, was filled in pretty much along the lines of what ahoffmann suggests (I tried filling that file in directly also as suggested) but, very strangely, they did not take.

By "not take" I mean they did not work and the routes did not show up when I executed "route -nN".

I did not go very far with shivsa's suggestion as I wasn't exactly sure where in the sequence to put it.  Also, sudo requires the root password, which I don't like to type into a script.  And when attempting to execute the command in a console, it said it could not find the "ip" command (I was not logged on as route).

Anyway, things work.  But Linux...I hate going to DHCP for a bit, and YAST for a little bit more, and mucking about in this and that rinky dink config file for the last little bit.  What is this? Windows?
LVL 51

Expert Comment

ID: 9849640
> .. very strangely, they did not take
it will be used when initialising the corresponding runlevel, or at boot

Using /etc/sysconfig/network/if-up.d/wlan0-up or /etc/sysconfig/network/routes is rather a matter of your taste, unfortunatelly SuSE has it's own taste too, so take care ..

Author Comment

ID: 9850727

This is a PCMCIA card.  I wonder when it becomes active.  Even when I have the card inserted on boot up I see that, when the network interfaces become active, the wlan0 interface is tagged as "hotplug".  And seems to be skipped until later.  Maybe the ".../routes" are ignored because at the time they would be looked at during boot, there is no interface active.

But, they are ignored.  I have tried rebooting after setting the route file, and no dice.

"so take care..." - I would be interested in the details of the caution.
LVL 51

Expert Comment

ID: 9851772
> .. hotplug ..
sorry, I'm not (yet) used to this mechanism at SuSE ..
In this case the wlan0-up script might be the better, and more system-conform, solution

Expert Comment

ID: 9912393
I have SuSE 9.0 installed and have the same problem you have.
I Made a little bash script to set the default gateway:
#! /bin/bash

echo "* Setting up Wireless lan.."
echo "* Releasing current IP"
/bin/ifdown-dhcp wlan0 >/dev/null
echo "* Deleting current route"
ip route flush table main
echo "* Requesting IP for wlan0"
/bin/ifup-dhcp wlan0
echo "* Setting route"
GATE=`/bin/ifstatus-dhcp wlan0|grep GATEWAY|cut -c13-30`
echo "* Setting default gateway to $GATE"
ip route add default via "$GATE" dev wlan0

I made some LN's from /sbin to /bin in order to make the script work also als non-root and asdjusted the /etc/sudoers file:
YourUserName  ALL=NOPASSWD:/etc/init.d/wlanup
and execute script 'sudo yourscriptname'

Please note im beginner to linux and you probably know a more fancy script :)

I also experienced problems with resolving, i managed to solve this by using dhcpcd als dns client (change this in /etc/sysconfig/network/dhcp and set BIN to 'dhcpd')

Please drop a note if this helps you ;)

Author Comment

ID: 9918276
I'm putting bets on me being greener in Linux than you, and undoubtedly your stuff will help me understanding a number of things.  Like how dhcp is invoked and how sudo works.  Good things to know.  Thanks.

Although, I'm not so sure about sudo.  And it looks like you set it up so no password is required?  I would think that might be a security risk.

Like I say, for me, putting the line "ip route add default via dev wlan0" in a script in  "/etc/sysconfig/network/if-up.d" seems to complete my routing when I plug my card in with no need of "sudo".

Expert Comment

ID: 9919015
I made this script because its for my laptop and the default gateway is different each time (multiple wireless networks).
Your right about the security thing, but its only possible to execute that certain script with root rights and as long as the scripts had the right chmod i guess its o.k.

Your solution far easyer, im gonne look if its posible to combine our solutions.
Greets ! :)

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question