+ -

Pages

Monday, September 2, 2013

A quick look at some basic networking commands

http://vishalthakur.com


IFCONFIG

This command prints the information on the available network interfaces. You can use this command to look at the IP address that your interfaces are using, the subnet, broadcast address etc.
Sample output:
# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:AE:49:76 
          inet addr:10.10.10.8  Bcast:10.10.10.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feae:4976/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:19526 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3932 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1633624 (1.5 MiB)  TX bytes:564499 (551.2 KiB)

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1776 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1776 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:539420 (526.7 KiB)  TX bytes:539420 (526.7 KiB)

In the above example, the IP address of eth0 (the Ethernet interface) is 10.10.10.8
You can also use this command to manually assign an IP address to an interface:
#ifconfig eth0 10.10.10.7 netmask 255.255.255.0

ROUTE

This command can be used to show the current gateway address that the network is using. You can also use this command to manually assign a gateway to the interface of your choice.
Sample output:
# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.10.10.0      *               255.255.255.0   U     0      0        0 eth0
default         10.10.10.1      0.0.0.0         UG    0      0        0 eth0

#route add default gw 10.10.10.1 eth0

HOSTNAME

This command can be used to print the current hostname of the machine.
You can also use this command to change the hostname of the machine but the change is not permanent – it does not survive a reboot.
#hostname
old_hostname
#hostname new_hostname
#hostname
new_hostname

Another way of achieving above results:
#echo “new_hostname” >> /proc/sys/kernel/hostname
#hostname
new_hostname

Changing the hostname permanently:

Change the hostname in the file /etc/sysconfig/network
Save the file with the new name and that'll do the job.

MANUALLY CHANGING THE IP ADDRESS OF A MACHINE

You can change/assign IP addresses to your Linux machine by changing the interface file manually. The file that holds that information is:
ifcfg-‘interface’
Eg. ifcfg-eth0
To see what the configuration is, run this command:
#cat /etc/sysconfig/network-scripts/ifcfg-eth0 (to see the IP configuration of eth0, in this case).
Sample output:
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:AE:49:76
TYPE=Ethernet
UUID=c906df68-4958-447e-8993-d6bf07aef7f4
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=10.10.10.8
NETMASK=255.255.255.0
GATEWAY=10.10.10.1
DNS1=8.8.8.8

Some important attributes from this file:

DEVICE – this specifies the actual device, like eth0, eth1, lo etc.
ONBOOT – this tells the machine to activate the interface while its being turned on or leave it deactivated till its manually brought up by the user
BOOTPROTO – very important, this decides whether the  IP is manually assigned or is assigned dynamically by DHCP (change it to DHCP for that)
DNS1 – this defines the DNS that the machine is going to be using (in this example its using google’s DNS, which is free service provided by google)
Make sure you restart the network service everytime the config file is changed.
#service network restart
5 RakshaTec: A quick look at some basic networking commands http://vishalthakur.com IFCONFIG This command prints the information on the available network interfaces. You can use this command ...

No comments:

Post a Comment

< >