sslug-teknik team mailing list archive
-
sslug-teknik team
-
Mailing list archive
-
Message #02208
Re: ifconfig
Send reply to: sslug-teknik@xxxxxxxx
From: "Morten" <morten@xxxxxxxxx>
To: <sslug-teknik@xxxxxxxx>
Date sent: Sat, 13 Feb 1999 11:31:28 +0100
Subject: [TEKNIK] ifconfig
> Hej,
>
> Et af de problemer jeg nu sidder med er i ifconfig.
> Jeg kan ikke gennemtvinge en ændring af ip addressen for linux boxen (for slet ikke at nævne at X miljøet ligger i ruiner !!!!)
> #ifconfig eth0 down
> #ifconfig eth0 del address 192.168.0.10
> kommer ud med en fejl !
> det samme gælder for:
> ifconfig eth0 address 192.168.0.1 (for at ændre !)
> det samme med add address.
>
> Hjælpen er yderst kærkommen!!!
> (Jge ville meget nødigt være nød til at geninstallere fra Scratch !) - OG endnunødigere installere et M$ produkt
>
> Hilsen
>
> Morten
>
Jeg har selv brugt følgende lille script når jeg skulle ændre
ipnummer på en kørende Linuxbox, jeg vil tro at du skulle kunne
bruge det til at sætte ipnummer på en box der ikke har et.
Jens
[ KLIP ]
#!/bin/sh
#
# Change ip address on ethernet interface
# Hardcoded to handle class c adresses only
# Will work remotely via telnet connection if called like this:
# nohup ./ipchange <ip-address> [gateway] [interface] &
# and will not even break the telnet connection !
#
# 13 Feb 1999, Jens Knudsen
#
# Make sure user called script with at least 1 argument
if [ -z $1 ]
then
echo " "
echo "syntax:"
echo "-------"
echo "$0 ip-address [gateway] [interface]"
echo " "
echo "if gateway is not given, ip-address is used as gateway"
echo "if interface is not given, \"eth0\" is used as gateway"
echo " "
exit 1
fi
# Set name of interface
if [ -z $3 ]
then
INTERFACE="eth0"
else
INTERFACE=$3
fi
# Isolate the four octets in ip-address argument
ADDRESS=$1
OCTET1=`echo $ADDRESS | awk -F . ' { print $1 }'`
OCTET2=`echo $ADDRESS | awk -F . ' { print $2 }'`
OCTET3=`echo $ADDRESS | awk -F . ' { print $3 }'`
OCTET4=`echo $ADDRESS | awk -F . ' { print $4 }'`
# Define class c broadcast address
BROADCAST=$OCTET1.$OCTET2.$OCTET3.255
# Define netmask
NETMASK=255.255.255.0
# Define network
NETWORK=$OCTET1.$OCTET2.$OCTET3.0
# Define gateway (the machine itself if no second parameter given
to ipchange)
if [ -z $2 ]
then
GATEWAY=$ADDRESS
else
GATEWAY=$2
fi
echo " "
echo "Changing interface $INTERFACE to:"
echo "-----------------------------------------------------------"
echo "ADDRESS $ADDRESS BROADCAST $BROADCAST"
echo "NETMASK $NETMASK NETWORK $NETWORK"
echo "GATEWAY $GATEWAY"
echo " "
# close ethernet interface
echo "Removing and closing existing ethernet interface"
ifconfig $INTERFACE down
# open ethernet interface with new ip adress
echo "Assigning new address to ethernet interface"
ifconfig $INTERFACE $ADDRESS broadcast $BROADCAST
netmask $NETMASK up
# show ifconfig
echo "Show ethernet configuration"
echo "-------------------------------------------------------"
ifconfig $INTERFACE
# do the routing
echo "Add routing so interface can be reached and used"
route add -net $NETWORK netmask $NETMASK $INTERFACE
route add default gw $GATEWAY metric 1
# Show routing information"
echo "Show routing information"
netstat -r
References