Advertisement
s243a

setupStaticIP() - /etc/rc.d/rc.network

Oct 9th, 2016
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.74 KB | None | 0 0
  1. # lines 169 to 212 of /etc/rc.d/rc.network
  2. # http://www.pearltrees.com/s243a/setupstaticip-puppylinux/id16440741
  3. # cutdown version of this function (can't just source net-setup.sh...)
  4. # config file will include IP_ADDRESS, NETMASK, DNS_SERVER[12], GATEWAY
  5. setupStaticIP()
  6. {
  7.     BROADCAST=$(ipcalc -b "$IP_ADDRESS" "$NETMASK" | cut -d= -f2)
  8.     echo "configuring interface $INTERFACE with static ip..."
  9.     #ifconfig "$INTERFACE" down
  10.    
  11.     # do the work
  12.     ifconfig "$INTERFACE" "$IP_ADDRESS" netmask "$NETMASK" broadcast "$BROADCAST" #up
  13.     if [ $? -eq 0 ];then
  14.         # Configure a nameserver, if we're supposed to.
  15.         # This now replaces any existing resolv.conf, which
  16.         # we will try to back up.
  17.         if [ "$DNS_SERVER1" != "0.0.0.0" ] ; then
  18.             # remove old backups
  19.             rm /etc/resolv.conf.[0-9][0-9]* 2>/dev/null
  20.             # backup previous one
  21.             mv -f /etc/resolv.conf /etc/resolv.conf.old
  22.             echo "nameserver $DNS_SERVER1" > /etc/resolv.conf
  23.             if [ "$DNS_SERVER2" != "0.0.0.0" ] ; then
  24.                 echo "nameserver $DNS_SERVER2" >> /etc/resolv.conf
  25.             fi
  26.         fi
  27.    
  28.         # add default route, if we're supposed to
  29.         if [ "$GATEWAY" ] ; then
  30.             route add -net default gw "$GATEWAY" #dev $INTERFACE
  31.             if [ $? -eq 0 ];then #0=ok.
  32.                 echo "Default route set through $GATEWAY."
  33.             else
  34.                 echo -e "Could not set default route through $GATEWAY.  Please try again.\nNote that Puppy has tried to do this:\nroute add -net default gw $GATEWAY" #dev $INTERFACE"
  35.                 #ifconfig "$INTERFACE" down
  36.                 return 1
  37.             fi
  38.         fi
  39.        
  40.         return 0
  41.     else
  42.         echo -e "Interface configuration failed; please try again.\nWhat Puppy has just tried to do is this:\nifconfig $INTERFACE $IP_ADDRESS netmask $NETMASK broadcast $BROADCAST up"
  43.         #ifconfig "$INTERFACE" down
  44.         return 1
  45.     fi
  46. } #end of setupStaticIP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement