09 Sep 28
Here, i would like to share with you all some commands that is useful in extracting network information from the OS.
1. Extracting IP of the current machine
ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{print $1}'
2. Getting the Gateway of the current machine
route -n | grep 'UG[ \t]' | awk '{print $2}'
3. Updating the network settings
// ifconfig <network interface> <ip> netmask <subnetmask> broadcast <broadcast address> ifconfig eth0 192.168.0.10 netmask 255.255.255.0 broadcast 192.168.0.255
4. Updating Gateway
// in order to achieve this, we need to first delete the // existing gateway entry and then add the new one route del default // route add -net default gw <gateway address> netmask 0.0.0.0 dev eth0; route add -net default gw 192.168.0.255 netmask 0.0.0.0 dev eth0