Solved

Login or Boot up Command

Posted on 2003-11-29
10
733 Views
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 192.168.1.1 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).
0
Comment
Question by:robertjbarker
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 6

Author Comment

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

Assisted Solution

by:shivsa
shivsa earned 125 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 192.168.1.1 dev wlan0

0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 125 total points
ID: 9846359
echo 'default 192.168.1.1 0.0.0.0 wlan0' >>/etc/sysconfig/network/routes

There should be a way to configure it in yast/yast2 too ...
0
 
LVL 6

Author Comment

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

       ip route add default via 192.168.1.1 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?
0
 
LVL 51

Expert Comment

by:ahoffmann
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 ..
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 6

Author Comment

by:robertjbarker
ID: 9850727
ahoffmann,

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.
0
 
LVL 51

Expert Comment

by:ahoffmann
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
0
 

Expert Comment

by:DaPozt
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:
[code]
#! /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
[/code]

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:
[code]
YourUserName  ALL=NOPASSWD:/etc/init.d/wlanup
[/code]
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 ;)
0
 
LVL 6

Author Comment

by:robertjbarker
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 192.168.1.1 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".
0
 

Expert Comment

by:DaPozt
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 ! :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now