LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   1 Laptop needs setting uo for work and home (https://www.linuxquestions.org/questions/linux-newbie-8/1-laptop-needs-setting-uo-for-work-and-home-666127/)

sneaky 08-28-2008 02:42 PM

1 Laptop needs setting uo for work and home
 
I use my laptop at home and work and I do not want to keep changing default gateways, ip ranges and dns's etc what is the best way to get round this.

Thanks

Chris

Also if I have an ip address of 172.16.0.13 and a linksys broadband router of 192.168.1.1 how do make them talk to each so that I can access the internet.

Poetics 08-28-2008 03:12 PM

I actually use two scripts that I coded up, one for use at work, and one for at home. Of course these are greatly simplified, but you get the idea.

Code:

# cat home
#!/bin/bash
ifconfig eth0 down
ifconfig wan0 down
ifconfig eth0 up
ifconfig eth0 192.168.2.14 255.255.255.0
route add default gw 192.168.2.1
echo "192.168.2.1" > /etc/resolv.conf

# cat work
#!/bin/bash
ifconfig eth0 down
ifconfig wan0 down
iwconfig wan0 ESSID="Work AP" AP="blah" key="Secret"
ifconfig wan0 up
ifconfig wan0 194.16.8.37 255.255.248.0
route add default gw 194.16.8.16
echo "194.16.8.16 > /etc/resolv.conf

As to how to get your router and computer talking, if they're on different subnets (172.16 and 192.168) you're likely to have problems. The easiest method may be to run your dhcp client daemon (`dhcpcd` on Slackware) and pick up an address and DNS settings directly from the router in question.

sneaky 08-28-2008 03:18 PM

Thanks for the scripts.

I am a novice Linux person so excuse the daft questions.

1)What do I call the files including extensions.

2)Which Directory do I put them in.

3)How and when do I run the one I want.

I have just had a thought is it possible to use network manager and use the wired connection for work and the wireless for home.

Chris

Poetics 08-28-2008 03:38 PM

I tend to use the GUI as little as possible -- perhaps that's due to my Slackware background, which is why I have actually never used the network manager.

You may put these scripts really anywhere you'd like -- I myself just keep them in root's home directory (/root), for easy access when I `su` to root. Before using the above scripts for your own setup, make sure to read the ifconfig man page, and if applicable (for wireless), iwconfig.

To write those scripts, I just opened up vi (a text-editing program) from the command line and entered the above, saving the first as 'home' and the second as 'work'. You have to make sure they are executable, by using the `chmod` program. Again, read its man page for additional help. Unlike in Windows, there is no specific extention that makes a script or program executable; it's all handled through the file's permissions, which again are edited by `chmod`.

To execute those commands, I just run `su -c "/root/home"` or `su -c "/root/work"` as necessary. Others may have their own favored methodologies for doing this, but mine works for me and is fairly straightforward. The important part is that these files have to be run as root, because normally ifconfig, iwconfig, route, and resolv.conf aren't able to be accessed by normal, unprivileged users.

Also, if you update your profile information to include your distribution, it can help people here at LQ tailor their responses to your specific distro.

theYinYeti 08-28-2008 03:43 PM

I don't know what distribution you're using, but Mandriva has something called "Network profiles", configured in GUI from the Mandriva Control Center.
You should probably investigate and see if your distribution provides something equivalent.

Yves.

sneaky 08-28-2008 03:55 PM

I use Fedora 9. I will update my profile.
I have set the files up and chmod 100 the files but when I try to run them with su -c "workh" it comes back with command not found.

Am I right in thinking I can setup the wired to one subnet and wireless to another.

Thanks for your time

Chris

Poetics 08-28-2008 04:42 PM

That you can -- something with using su -c however is that you need to tell it exactly where the file is, since it's likely not in your PATH. If your 'workh' is in /root, try `su -c "/root/workh"` instead.

arizonagroovejet 08-28-2008 05:03 PM

Why don't you just use DHCP? Your router will offer it, chances are where you work does too.

IsaacKuo 08-28-2008 05:12 PM

I second the recommendation for DHCP. If you want a static IP at home, then you can configure your DHCP server (probably your router) to always serve up the same IP address for your laptop's MAC address.

sneaky 08-28-2008 05:46 PM

Thanks boys.

That is what I decided to do - seems like much less hassle.

Thanks for all your advice

Chris


All times are GMT -5. The time now is 12:33 AM.