LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 12-06-2007, 03:18 AM   #1
dkarang
LQ Newbie
 
Registered: Dec 2007
Distribution: slackware
Posts: 3

Rep: Reputation: 0
Help me automate my network configuration


I'm trying to automate network setup for my laptop, particularly switching between wired/wireless connection according to availability.
I get the feeling udev or hal or something like that can do what I want, but I can't find a good entry point for the documentation.

Here's my setup :

Slack 12 just installed on laptop, with wired (eth0) and wireless (eth1) NICs. Both interfaces configured with static IPs on the same subnet. When the ethernet cable is plugged in, everything works properly. If the cable is not plugged in, the network is unreachable until I do :

# route del default
# route add default gw $MY_GATEWAY dev eth1

Does anyone have a way to do this automaticaly whenever cable/wifi state changes? I could write a script to set everything up by checking sysfs, along with judicious pinging, but I don't want to have to run it by hand every time.
 
Old 12-06-2007, 10:34 AM   #2
agentc0re
Member
 
Registered: Apr 2007
Location: SLC, UTAH
Distribution: Slackware
Posts: 200

Rep: Reputation: 34
Welcome to LQ and the Slack community!

So your wired network has the same subnet as your wireless? if you changed it to be different ones i think you wouldn't have as much trouble.
here's an example configuration.

wired: 10.1.1.0/24
wireless: 10.2.1.0/24

edit /etc/rc.d/rc.inet1.conf
Code:
# Config information for eth0:
IPADDR[0]="10.1.1.100"
NETMASK[0]="255.255.255.0"
USE_DHCP[0]=""
DHCP_HOSTNAME[0]=""

# Config information for eth1:
IPADDR[1]="10.2.1.100"
NETMASK[1]="255.255.255.0"
USE_DHCP[1]=""
DHCP_HOSTNAME[1]=""

# Default gateway IP address:
GATEWAY=""
Make sure gateway is blank.

then in your rc.local
Code:
route add default gw 10.1.1.1 dev eth0
route add default gw 10.2.1.1 dev eth1
There might be a better way to do this and to be honest im not sure if this will work. it makes sense and it should work i just don't have a setup to test on.
 
Old 12-06-2007, 11:36 AM   #3
dkarang
LQ Newbie
 
Registered: Dec 2007
Distribution: slackware
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for your answer.

Unfortunately, it's not my network at work, so I can't change anything other than my own configuration: everything must be in one subnet. On top of that, I doubt my home router can handle two different subnets.

Here's an example of what I'm looking for, to make it clearer :

I come in to work in the morning, use the cable available at my desk. Later on I have to work in another room for a meeting, so I use the wireless connection. In the afternoon I go home, connect through my home network. All network configuration happens silently, whithout me having to do anything other than plug/unplug the cable or boot the laptop.
 
Old 12-06-2007, 04:02 PM   #4
urka58
Member
 
Registered: Nov 2003
Distribution: slackware 15
Posts: 546

Rep: Reputation: 43
My laptop works this way..
Office- IP address assigned by DHCP (win 2003 server)
Home - Small router on static IP addresses assigned net (2 machines + laptop)

I just created a second /etc/rd.d/inet1.conf, let's say /etc/rc.d/inet2.conf properly configured.
As I have only one ethernet port (eth0) my /etc/rc.d/inet1.conf is like this

# Config information for eth0:
IPADDR[0]=""
NETMASK[0]=""
USE_DHCP[0]="yes"
DHCP_HOSTNAME[0]=""

# Default gateway IP address:
GATEWAY=""

My second "/etc/rc.d/inet2.conf" is like this

# Config information for eth0:
IPADDR[0]="192.168.1.4"
NETMASK[0]="255.255.255.0"
USE_DHCP[0]=""
DHCP_HOSTNAME[0]=""

# Default gateway IP address:
GATEWAY="192.168.1.1"

Now you need a small modification of your /etc/rc.d/inet1, very simple..at the very beginning of the script you'll find
. /etc/rc.d/rc.inet1.conf (the first uncommented line)
where /etc/rc.d/inet1.conf is "sourced" by the script. Change to a conditional sourcing this way

if cat /proc/cmdline | grep -w "Office" 1> /dev/null 2> /dev/null; then
. /etc/rc.d/rc.inet1.conf
else
. /etc/rc.d/rc.inet2.conf
fi

You are almost done, just one step..
Modify your /etc/lilo.conf from somethgig like

image = /boot/bzImage-2.6.23.1
root = /dev/hda3
label = Slack12
read-only

to

image = /boot/bzImage-2.6.23.1
root = /dev/hda3
label = Slack12-Office
append = "Office"
read-only
image = /boot/bzImage-2.6.23.1
root = /dev/hda3
label = Slack12-Home
read-only

Of course you have to change this according to your configuration. Remember to launch lilo in order this take effect. The Kernel will not complain for such unusual boot parameter.
When you boot is just a matter of choice
Hope this helps
ciao
 
Old 12-07-2007, 02:17 AM   #5
evilDagmar
Member
 
Registered: Mar 2005
Location: Right behind you.
Distribution: NBG, then randomed.
Posts: 480

Rep: Reputation: 31
Install NetworkManager.
 
Old 12-07-2007, 03:25 AM   #6
urka58
Member
 
Registered: Nov 2003
Distribution: slackware 15
Posts: 546

Rep: Reputation: 43
Quote:
Originally Posted by evilDagmar View Post
Install NetworkManager.
Only dynamic IPs are allowed with this software...
Ciao
 
Old 12-07-2007, 04:05 AM   #7
evilDagmar
Member
 
Registered: Mar 2005
Location: Right behind you.
Distribution: NBG, then randomed.
Posts: 480

Rep: Reputation: 31
If you want automated, then get automated.

Statically configured hosts are rather not automated. Set up a DHCP daemon at home and stop worrying about this stuff, because you can be pretty sure that any wireless network you go to is going to be using DHCP to hand out IP addresses. We are long past the point where people should be dorking around with configuring individual machines on their network when they don't need to.

Last edited by evilDagmar; 12-07-2007 at 04:06 AM.
 
Old 12-07-2007, 05:00 AM   #8
dkarang
LQ Newbie
 
Registered: Dec 2007
Distribution: slackware
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for all the answers - I'm getting a feeling I shouldn't be messing with all of this, but then I wouldn't be running slack if I didn't enjoy it .

I actualy have DHCP at home for guests, it's just that my cheapo DSL router ocassionaly decides to take a break. I also want to log in to the laptop from my other machines - it's not configurable enough to give me the same address every time.

For what it's worth, the solution i'm sticking to for now is using a script to check which connection is up and ping the gateways to find where I am. I'm running it at startup, and by hand from a panel launcher whenever appropriate.

If someone has a way to run this whenever network state changes I'm all set.
 
Old 12-07-2007, 08:00 AM   #9
urka58
Member
 
Registered: Nov 2003
Distribution: slackware 15
Posts: 546

Rep: Reputation: 43
So.. I don't believe it is possible your laptop can guess where you are.

Another method is you create an alias for your ethernet port this way

ifconfig eth0:1 192.168.x.x netmask 255.255.255.0
route add default gw 192.168.x.1

Just put these commands on /etc/rc.d/rc.local (or create a new section in /etc/rc.d/rc.inet1.conf) and it will set up your ethernet port for your home configuration.

Hope this helps

Ciao
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Slackware 10 network configuration. Problem with 8139 network card drivers ! Padmakiran Linux - Networking 8 03-27-2007 06:48 AM
LXer: Speaking Unix, Part 6: Automate, automate, automate! LXer Syndicated Linux News 0 01-04-2007 09:54 AM
Network Configuration in Debian (laptop network card) legendaryhwk Linux - Networking 6 04-06-2006 03:59 AM
Network Configuration Hanging in FC4 After Using Wireless Network Wizard Trip in VA Linux - Wireless Networking 2 07-18-2005 08:32 AM
Automate Network Start? Glenn Butzlaff Linux - Newbie 2 06-19-2003 07:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration