Tuesday, March 19, 2024
HomeLinuxLinux Networking Commands - Explained

Linux Networking Commands – Explained

On Red Hat Linux the network communications between nodes is done through the software network interfaces (real or virtual) related with the physical interfaces.(real). The following are the keys files in order to integrate a system on the network

/etc/hosts:

The main propose of this file is provide local DNS resolving. It can be used to resolve hostnames in small networks without DNS server

# cat /etc/hosts

127.0.0.1  localhost

127.0.0.1  *india*

192.168.0.161 server

# The following lines are desirable for IPv6 capable hosts

::1     localhost ip6-localhost ip6-loopback

On this system server hostname is resolved to 192.168.0.161

/etc/resolv.conf:

in this file is where the connection with a DNS server is configured

# cat /etc/resolv.conf

search myhome.io

nameserver 192.168.0.161

This system will forward all myhome.io (other domains) DNS queries to 192.168.0.161 DNS server

/etc/sysconfig/network

In this file is where the network activation is configured, It also setup the system hostname

# cat /etc/sysconfig/network

NETWORKING=yes

NETWORKING_IPV6=yes

HOSTNAME=server

With the parameter ‘NETWORKING=no’ the system will not have network connection

/etc/sysconfig/network-scripts/ifcfg-*

These are the configuration scripts (real or virtual) associated with the physical interface (real). For examples the configuration script for eth0 network interface is /etc/sysconfig/network-scripts/ifcfg-eth0

#cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=none

HWADDR=d0:27:88:11:4d:71

ONBOOT=yes

NETMASK=255.255.255.0

IPADDR=192.168.0.161

GATEWAY=192.168.0.3

TYPE=Ethernet

DEVICE=lo

IPADDR=127.0.0.1

NETMASK=255.0.0.0

NETWORK=127.0.0.0

# If you’re having problems with gated making 127.0.0.0/8 a martian,

# You can change this to something else (255.255.255.255, for example)

BROADCAST=127.255.255.255

ONBOOT=yes

NAME=loopback

* These interfaces can activated/deactivated individually with the commends ifup/ifdown

#ifup eth0

Activates network interfaces eth0 as specified on /etc/sysconfig/network-scripts/ifcfg-eth0

#ifdown eth0

Deactivated interfaces eth0

* If the interfaces.eth0 is configured with the parameter “ONBOOT=yes” it will be activated as specified on ifcfg-eth0 with the commend

#/etc/init.d/network start

And deactivated with

#/etc/init.d/network stop

All interfaces. Configured with ONBOOT= yes will be activated/deactivated at the same time with the commend ‘/etc/init.d/network start/stop’

* The following are some useful options to be considered on /etc/sysconfig/network-scripts/ifcfg-* file

BOOTPROTO=”dhcp”

The interfaces witll get the ip with dhcp protocol

PEERDNS=”yes”

when is BOOTPROTO=”dhcp” the dhcp server provides an ip to the interfaces and the DNS server on /etc/resolv.conf

USERCTL=”yes”

Non-root users can activate/deactivate the network interfaces.

ROUTE:

This command displays/change the routing table information.

#route -n

Displays system routing information.

# route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref   Use Iface

0.0.0.0         192.168.0.3     0.0.0.0         UG   100   0       0 eth0

192.168.0.0     0.0.0.0         255.255.255.0   U     0     0      0 eth0

#route add default gateway to 192.168.10.4

# route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref   Use Iface

0.0.0.0         192.168.0.4     0.0.0.0         UG   100   0       0 eth0

192.168.0.0     0.0.0.0         255.255.255.0   U     0     0       0 eth0

IFCCONFIG

With this command the network interfaces can be configured overwriting the values on   ifcfg-* files.

#ifconfig

Shows the network configuration of all configured network interfaces.

#ifconfig eth0 192.168.0.161

It assigns the ip 192.168.0.16 to the network interface eth0

#ifconfig eth0:1 192.1668.0.161

It creates a virtual network interface eth0:1 from eth0 with the ip 192.168.0.161

#ifconfig eth0 up/down

Activates/deactivates eth0 networking interfaces.

DHCLIENT:

This command is a dhcp-client that queries dhcp network interface to any active dhcp server

#dhclient eth0

Configures eth0 with the dhcp configuration retrieved.

# System-config-network

This command launches a graphical application that configures the network interface, including wireless interfaces.

ARP:

The arp command manages the relation between IP address and MAC address.

#arp -a

?(192.168.10.223)at 00:0c:29:4b:ce:ed [ether] on eth0

?(192.168.10.6) at 00:0c:29:21:f7:7f [ether] on eth0

Shows all arp entries cached by the system

# arp -d hostname

removes hostname arp entry

# arp -s hostname

arp entry with mac MAC

ETHTOOL:

 Display/changes the network card settings.

# ethtool eth0

settings foreth0:

current message level:0*00000007 (7)

link detected: yes

This command verifies that there is a network wire plugged on eth0 network card

RELATED ARTICLES
- Advertisment -

Most Popular

Recent Comments