I will list any network related stuff here.
First out is a simple script to get your current default gateway from the 'route' command:
#!/bin/sh
route -n get default|grep gateway||awk '{print $2}'
Save it for example as '/usr/local/sbin/default_gateway.sh', chmod 755, and you will always get the default gateway by just typing
default_gateway.sh
Not so exciting for your LAN, as the default gateway probably (almost) never will change, but useful when you access many different WLANs.
Another simple script to print the current IP (if any) for a NIC:
#!/bin/sh
# Check for at least one argument
if [ -z $1 ]; then
echo "Usage:"
echo "$0 nic_interface"
echo "where 'nic_interface' is one of the following interfaces:"
echo `ifconfig -l`
exit 1
fi
NIC=$1
ifconfig $NIC |grep inet|grep -v inet6| awk '{print $2}'
Save it for example as '/usr/local/sbin/ip_nic.sh', chmod 755, and you will get a NICs IP by typing
ip_nic.sh 'nic_interface'
Here are some tricks to change IP, DNS, and default gateway 'on the fly' when you switch between WLANs frequently, or when you are in the middle of two or more Access Points and the strongest signal becomes the weakest.
Backup your current IP for the WLAN NIC, DNS and default gateway settings, and then remove the current default route.
In my case the NIC is called 'ath0' (check with 'ifconfig' if you aren't sure about yours):
It is necessary to delete the current default route before getting the new network settings by DHCP.
Otherwise, you will only obtain a new IP and DNS settings, but continuing with the same old default route, which isn't what you want.
Then you run 'dhclient' with the name of your wireless NIC as argument.
dhclient ath0
If everything is OK, you will obtain new network settings from the new DHCP server.
Check using 'ifconfig' (IP), 'cat /etc/resolv.conf' (DNS), and 'netstat -nr' (default gateway).
When you want to disconnect from the WLAN, just kill the 'dhclient' program:
kill `cat /var/run/dhclient.pid`
Then restore your previous network settings:
cp /etc/resolv.conf~ /etc/resolv.conf
ifconfig ath0 down
ifconfig ath0 `cat /etc/ip_nic~` up
route delete default
route add default `cat /etc/default_gateway~`