I have two different networks available, but only one at a time. Some time one or the other network will be down. In order to connect to the network I have to change the configuration manually. Is there away to automate this using some scripts. Iam using opensuse 11.4
thanks and regards
Assuming that you are using the traditional method with yast / ifup then:
All configuration data will be stored in the directory /etc/sysconfig/network/
Configure your system for netA with yast.
Make backup copies of the configuration files. Example:
cp routes routes.netA
Now configure your system with yast to use netB
Use the diff command to see what files have changed. Example:
diff routes routes.netA
- For these config files who have changed make backup copies. Example:
cp routes routes.netB
Delete the backups for those files of *.netA which did not change
Write a shell script which will copy all the backups of one network to the original files and then restarts the network.
To restart the network, use (in the script)
I’m just adding a little detail to an excellent account of what is needed.
When you say “Connect to the Network” I think you really mean “connect to a different ISP gateway” – right?
If you’re connecting to the same physical network but connecting to a different ISP gateway and the network is otherwise unchanged, all you need to do is change the Default Gateway.
If you’re really connecting to two separate physical networks you may find that simply running different DHCP on each network, then simply physically unplugging from one network and plugging into the other network is easiest.
The scripts and YAST are one approach, you might also keep in mind that if you use a Network Manager, changing network settings (and if desired using a script to change network settings in the Network Manager) can work without requiring an explicit Service restart (if needed, the NM will do it for you automatically). Also, usually all Network Managers support profiles which means instead of a script you simply choose the new pre-configured profile and voila! - All done for you.