AOA All,
Is there any way to set interface IPs for a temporary period by running a script.
The scenario is that
I have a Server which has two interfaces, one of them is being used for local network and the other is for establishing connectivity through VPN, but in case of the unavailability of the service for connectivity I need to switch them to another medium (PTCL Broadband) which certainly has the different IPs. Now is there any way to change them for a temporary period through a script?.
Remember I don't want the users to give administrative level so that they can do it themselves.
Waiting for the reply. Thanks.
Best Regards,
Misam Shah
Setting Interface IPs temporarily through Script
-
- Lance Naik
- Posts: 32
- Joined: Mon May 04, 2009 4:08 pm
- Location: Hyderabad
- Contact:
yes, you can do it. all you need to do in the script is route delete default, ifconfig eth0 whatever, route add default gw newgwip.
install sudo, and set it up so that users can only run your script with sudo, and nothing else.
"remember"? huh? where did you originally specify it that i have to "remember" it? please fix your tone. i'm not your underling, and i don't have to "remember" any of your requirements.Remember I don't want the users to give administrative level so that they can do it themselves.
install sudo, and set it up so that users can only run your script with sudo, and nothing else.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
Forgive that little Doctor for the mistakelambda wrote:"remember"? huh? where did you originally specify it that i have to "remember" it? please fix your tone. i'm not your underling, and i don't have to "remember" any of your requirements.Remember I don't want the users to give administrative level so that they can do it themselves.
-
- Lance Naik
- Posts: 32
- Joined: Mon May 04, 2009 4:08 pm
- Location: Hyderabad
- Contact:
Well I never meant that. I'll be careful in future for the Tone as u mentioned.osama wrote:Forgive that little Doctor for the mistakelambda wrote:"remember"? huh? where did you originally specify it that i have to "remember" it? please fix your tone. i'm not your underling, and i don't have to "remember" any of your requirements.Remember I don't want the users to give administrative level so that they can do it themselves.
And thanks alot for your reply. One more thing dear that I am a begginer of Linux and working on Ubuntu and Fedora. Its quite tough need support from all of you experts, see m just a cadet.
Hope you'll not mind because I m new to the Linux Kakool. Thanks
AOA,
You can see the followuing script for example.
You can see the followuing script for example.
Code: Select all
#!/bin/bash
### uncomment the following line for debugging
#set -x
### Defining variables
## Interface connected to internet
EXTDEV=eth0
### IP to check VPN connection
VPN_TEST=10.100.150.111
### IP to set for VPN
IPVPN=10.100.1.1
### VPN Gateway
VPN_GW=10.100.150.111
### Netmask for VPN
NM_VPN=255.255.0.0
### IP to Set PTCL
IPPTCL=192.168.1.150
### PTCL Gateway
PTCL_GW=192.168.1.1
### Netmask for PTCL
NM_PTCL=255.255.255.0
########################################################
### Dont change any thing
########################################################
if [ "$1" = "sw-ptcl" ]; then
ping -c5 $VPN_TEST >> /dev/null
if [ "$?" = "0" ]; then
ifdown $EXTDEV
ifconfig $EXTDEV $IPPTCL netmask $NM_PTCL up
route add default gw $PTCL_GW $EXTDEV
echo 1 > /proc/sys/net/ipv4/ip_forward
fi
else
if [ "$1" = "sw-vpn" ]; then
ifdown $EXTDEV
ifconfig $EXTDEV $IPVPN netmask $NM_VPN up
route add default gw $VPN_GW $EXTDEV
echo 1 > /proc/sys/net/ipv4/ip_forward
fi
fi
#############################################################
Note: i have not tested this script and nor do i say that this script will work 100%. This can be taken as an example to set the needed parameters.To run the script.
[root@ns1]; chmod +x <NAME_OF_SCRIPT>
### to switch to PTCL
[root@ns1]; <NAME_OF_SCRIPT> sw-ptcl
### to switch to VPN
[root@ns1]; <NAME_OF_SCRIPT> sw-vpn
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com