1827218 Members
2111 Online
109716 Solutions
New Discussion

default gateway chages

 
SOLVED
Go to solution
Jim Lynn_1
Occasional Advisor

default gateway chages

We are changing all the IP addresses in a network. It seems the default gateway gets added by itself even though we are changing it.Here is the script we use to change it.:

2) clear
echo "Enter the new IP Address"
read new_ip_add
echo "Enter the new Gateway"
read new_gateway
echo "Enter the new Netmask"
read new_netmask

cp /etc/rc.config.d/netconf /tmp/netconf.$dt
cp /etc/hosts /tmp/hosts.$dt
cp /var/adm/inetd.sec /tmp/inetd.sec.$dt

############### Changing netconf ##############################
sed 's/^IP_ADDRESS\[0\]=.*/IP_ADDRESS\[0\]='$new_ip_add'/g' /tmp/netconf
.$dt > /tmp/netconf.tmp
sed 's/^ROUTE_GATEWAY\[0\]=.*/ROUTE_GATEWAY\[0\]='$new_gateway'/g' /tmp/
netconf.tmp > /tmp/netconf.tmp.1
sed 's/^SUBNET_MASK\[0\]=.*/SUBNET_MASK\[0\]=255.255.255.0/g' /tmp/netco
nf.tmp.1 > /etc/rc.config.d/netconf

############## Changing /etc/hosts ##############################
ip=`grep "ISP Ether" /tmp/hosts.$dt | awk '{print $1}'`
sed 's/'$ip'/'$new_ip_add' /g' /tmp/hosts.$dt > /etc/hosts

############## Changing actual addresses ###########################

gw=`netstat -nr | grep default | awk '{print $2}'`
echo gateway is $gw
/etc/route delete net default $gw
/etc/route add net default $new_gateway
/usr/sbin/ifconfig lan0 inet $new_ip_add netmask $new_netmask

;;

Ideas ??? It defaults to the old network for some reason. These machines are still on HPUX 10.20
6 REPLIES 6
Stefan Farrelly
Honored Contributor

Re: default gateway chages

Take a closer look at the set_parms script - where it sets the gw, as this is the correct program to use to change it as it updates it in more than one place. If you use set_parms it will be fine, or else you will need to copy the logic set_parms uses when it sets the gw.
Im from Palmerston North, New Zealand, but somehow ended up in London...
Ravi_8
Honored Contributor

Re: default gateway chages

Hi Jim

I prefer using set_parms or changing in the files(/etc/rc.config.d) it self rather than using script.
which will be permanent after a reboot
never give up
Uday_S_Ankolekar
Honored Contributor

Re: default gateway chages

Instead of script I would use set_parms command directly to change network parameters.

use /sbin/set_parms ip_address and /sbin/set_parms addl_netwrk


Goodluck

-USA..
Good Luck..
Ron Kinner
Honored Contributor
Solution

Re: default gateway chages

You have:

/etc/route add net default $new_gateway


it should be:

/etc/route add net default $new_gateway 1

Note the "1" which indicates that the default gateway is remote. The command will fail without the 1 since the default gateway's ip address is not local.

You might also want to restart inetd with

inetd -c

This should cause it to reread your netconf file and pick up the changes.

Ron
Ivajlo Yanakiev
Respected Contributor

Re: default gateway chages

Hi

do not use set_parms
you will need reboot :)
This is very funy ==> unix and reboot :)
If you want ot setup
default gateway for temporaly
usage:
# route add net default 1

If you want parmanently change or set gateway ==>
edit /etc/rc.config.d/netconf
and it's ENOUGH (but will work after reboot)

ROUTE_DESTINATION[0]="default"
ROUTE_MASK[0]=""
ROUTE_GATEWAY[0]=
ROUTE_COUNT[0]=1
ROUTE_ARGS[0]=""

Steve Labar
Valued Contributor

Re: default gateway chages

If you add a new gateway using a script, it doesn't remove the old gateway automatically. You will need to do a route delete default before you can add the new one.

Good Luck.

Steve