Showing posts with label Networking. Show all posts
Showing posts with label Networking. Show all posts

Host-name Configuration Options in Linux

Back

During the boot process, the network services looks to the /etc/sysconfig/network file to define the value of the local host-name. It's okay if that host-name is set as a FQDN like tester1.example.com. As configured earlier, it's a simple file, where the host-name may be documented with a directive like the following.

HOSTNAME = tester1.example.com

You can change the value of the hostname with the hostname newname command. 

/etc/resolv.conf file in Linux

Back

The standard file for documenting the location of DNS servers is still /etc/resolv.conf. Typically, it'll have one or two entries, similar to the following.

search example.com
nameserver 192.168.122.1

The search directive appends the example.con domain name to searches for simple host-names. The name-server directive specifies the IP address of the configured DNS server. If in doubt about whether the DNS server is operational, run the following command :

# dig @192.168.122.1  mheducation.com

If needed, substitute the IP address associated with the nameserver directive in your /etc/resolv.conf file.

/etc/hosts file in Linux

Back

The /etc/hosts file is a static database of host-names / FQDN and IP addresses. It's suitable for small, relatively static networks. However, it can be a pain for networks where there are frequent changes. 

Every time a system is added or removed, you'll have to change this file not on the local system., but also on every other system on that network.

A simple version of file showing different local systems with their IP addresses : 

192.168.122.50    server1.example.com
192.168.122.150  tester1.example.com
192.168.100.100  outsider1.example.com
127.0.0.1              localhost.localdomain localhost








/etc/nsswitch.conf file in Linux

Back

The /etc/nsswitch.conf includes database search entries for everything from authentication to name services. As the name server switch file, includes the following entry, which determine what database is searched first.

hosts : files dns

When a system gets a request to search for a host-name such as outsider1.example.com, the preceding directive means the /etc/hosts file is searched first. If that name is not found in /etc/hosts, the next step is to search available configured DNS servers, normally using that configured in the /etc/resolv.conf file.

A few older software components use the /etc/host.conf file for this purpose. The entries in this file are simple, as they support searches of multiple entries in /etc/hosts, along with a search starting with that file, followed by a DNS server configured with the Berkeley Internet Name Domain (BIND) software.

multi on
order hosts,bind










Host-name Configuration Files in Linux

Back

RHEL 6 includes at least four hostname configuration files of interest : 

# /etc/nsswitch.conf

# /etc/hosts

# /etc/resolv.conf


/etc/sysconfig/network-scripts file in Linux

Back

Most of the files in the /etc/sysconfig/network-scripts directory are actually scripts. in other words, they are executable files based on a series of text commands, customized for network device type. If there's a special file in this directory , with a name like route-eth0. That special route would specify the gateway to a remote network address / network mask pair 

Example :

ADDRESS = 192.168.100.100
NETMASK = 255.255.255.0
GATEWAY = 192.168.122.1

/etc/sysconfig/network-scripts/ifcfg-etho file in Linux

Back

ifcfg-eth0 depends on how that first Ethernet network adapter was configured. For example, look at the situation where networking was configured only for the purpose of installation. If you did not configure networking when configuring the host-name during the GUI installation process, networking will not be configured on the system. In that case, ifcfg-eth0 file would contain the following directives, starting with the name of the device, along with the hardware address.

DEVICE = "eth0"
HWADDR = "F0:DE:F3:06:C6:DB"

By default, RHEL6 uses a device known as Network Manager.If a network card is controlled by that service, the following directive would be set to yes

NM_CONTROLLED = "yes"

The Network Manager is a service, to make sure it's running, execute the /etc/init.d/NetworkManager start command. Of course, if networking were not configured during the installation process, there's no reason for it to be activated during the boot process.

ONBOOT = "no"

The alternative to the Network Manager service is to configure it directly. For that purpose, the configuration file shown 

DEVICE = "eth0"
BOOTPROTO = "static"
DNS = "192.168.122.1"
GATEWAY = "192.168.122.1"
IPADDR = "192.168.122.50"
NETMASK = "255.255.255.0"
ONBOOT = "yes"

If you prefer to use a DHCP server, that static network address information would be omitted, and the following directive would be changed.

BOOTPROTO = "dhcp"






/etc/sysconfig/network-scripts/ifcfg-lo file in Linux

Back

lo, which is the loop-back address. That information is configured in the ifcfg-lo file in that directory. The contents of the file can help you understand how files in that directory are used for network devices. By Default, you should see the following entries in that file, starting with the name of the loop-back device.

DEVICE = lo

It;s followed by the IP address, net-mask, the network IP address, along with the corresponding broadcast address.

IPADDR = 127.0.0.1
NETMASK = 255.0.0.0
NETWORK = 127.0.0.0
BROADCAST = 127.255.255.255

The next entries specify whether the device is activated during the boot process, and the common name of the device.

ONBOOT = yes
NAME = loopback









/etc/sysconfig/network file in Linux

Back
If you run he ifconfig command and see no output, that means all network devices are currently inactive. If you run the ifconfig -a command and don't see an UDP in the output to any configured network device, that confirms the inactivity. 

The first thing to check in that case is the contents of the /etc/sysconfig/network configuration file. It's a pretty simple file. In general, you should see something similar to the following in that file.

NETWORKING = yes
HOSTNAME     = server1.example.com

If NETWORKING = no, then the /etc/sysconfig/network script does not activate any devices. The one other issue that may prevent networking from starting is the status of the script. Run the chkconfig --list network command. The output should look like :

0:off    1:off    2:on    3:on    4:on    5:on    6:off

If the settings next to the run-levels 3 and 5 are off, that's problem. To make sure a command service is active in appropriate run-levels, run the chkconfig network on command .

/etc/init.d/network file in Linux

Back

If there's trouble with a network configuration, one thing to check is the current status of the network. To do so, run the following command.

# /etc/init.d/network status

The command should list the configured and active devices. If a key device such as eth0 is not listed as active, that explains why the network seems to down. Key configuration files start with /etc/sysconfig/network. They continue with files in the /etc/sysconfig/network-scripts directory.

Sometimes mistakes happen. If you have deactivated  an adapter or just lost a wireless connection, one simple solution may be to restart networking. The following command restarts networking with current configuration files.

# /etc/init.d/network restart

If a simple restart of networking services doesn't work, then it's time to get into the files.

Network Configuration Files in Linux



Network configuration files determine whether networking is started during the boot process. If started ,these files also determine whether address and routes are configured statically as documented, or dynamically with the help of commands like dhclient.

Basic networking configuration only confirms that systems can communicate through their IP addresses. But that is not enough. Whether you are pointing to systems such as server1.example.com or URLs such as www.mheducation.com, network configuration is not enough if the host-name or (FQDN) fully qualified domain name is not working.

The most common cause of network problems is physical. The section assumes you have checked all network connections.On a VM, that means making sure the virtual network card wasn't accidentally deleted on VM (virtual machine) or on the physical host.

Network configuration Files

# /etc/init.d/network

# /etc/sysconfig/network

# /etc/sysconfig/network-scripts/ifcfg-lo

# /etc/sysconfig/network-scripts/ifcfg-etho

# /etc/sysconfig/network-scripts 






dhclient Command in Linux

Back

While the name of the command has changed from time to time, the functionality  has remained the same. Ever since Dynamic Host Configuration Protocol ( DHCP ) Servers were created to ration IPv4 address, commands have been needed by clients to call upon the services of that server. At this time, the key command is dhclient. When used with the device name  of a network card, it calls upon a DHCP server for an IP address and more. In fact, a command like the following may call on that DHCP server for  number of parameters 

# dhclient eth0

Generally, the network options that are configured through a DHCP server include the IP Address, the network mask, the gateway address for access to external networks ,and the IP address of any DNS servers for that network.

dhclient eth0 command not only assigns IP address information in the way done with the ifconfig command described earlier, but also it sets up the default route for the routing table shown with the route -n command. In addition it adds the IP address of the DNS server to the /etc/resolv.conf configuration file .

route Command in Linux

Back

The netstat command is versatile, it can help you see the channels available for network connections, interface statistics, and more. One important version of this command, netstat -r, displays routing tables that can tell you if the system knows where to send a message. 

Its functionality equivalent to the route command. When 
run on system, it's frequently run with the -n switch, to display address in numeric format. The routing table for the local system normally includes a reference to the local gateway address, coupled with the default route. 

The netstat -nr command should display the same thing. 

1. List All Ports (both listening and non listening ports)

List all ports using netstat -a
# netstat -a | more

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:30037         *:*                     LISTEN
udp        0      0 *:bootpc                *:*                            

Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     6135     /tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     5140     /var/run/acpid.socket

List all tcp ports using netstat -at
# netstat -at

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:30037         *:*                     LISTEN
tcp        0      0 localhost:ipp           *:*                     LISTEN
tcp        0      0 *:smtp                  *:*                     LISTEN
tcp6       0      0 localhost:ipp           [::]:*                  LISTEN

List all udp ports using netstat -au
# netstat -au

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
udp        0      0 *:bootpc                *:*
udp        0      0 *:49119                 *:*
udp        0      0 *:mdns                  *:*


2. List Sockets which are in Listening State

List only listening ports using netstat -l
# netstat -l

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:ipp           *:*                     LISTEN
tcp6       0      0 localhost:ipp           [::]:*                  LISTEN
udp        0      0 *:49119                 *:*

List only listening TCP Ports using netstat -lt
# netstat -lt

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:30037         *:*                     LISTEN
tcp        0      0 *:smtp                  *:*                     LISTEN
tcp6       0      0 localhost:ipp           [::]:*                  LISTEN

List only listening UDP Ports using netstat -lu
# netstat -lu

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
udp        0      0 *:49119                 *:*
udp        0      0 *:mdns                  *:*

List only the listening UNIX Ports using netstat -lx
# netstat -lx

Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     6294     private/maildrop
unix  2      [ ACC ]     STREAM     LISTENING     6203     public/cleanup
unix  2      [ ACC ]     STREAM     LISTENING     6302     private/ifmail
unix  2      [ ACC ]     STREAM     LISTENING     6306     private/bsmtp


3. Show the statistics for each protocol

Show statistics for all ports using netstat -s
# netstat -s

Ip:
    11150 total packets received
    1 with invalid addresses
    0 forwarded
    0 incoming packets discarded
    11149 incoming packets delivered
    11635 requests sent out

Icmp:
    0 ICMP messages received
    0 input ICMP message failed.

Tcp:
    582 active connections openings
    2 failed connection attempts
    25 connection resets received

Udp:
    1183 packets received
    4 packets to unknown port received.
.....
Show statistics for TCP (or) UDP ports using netstat -st (or) -su
# netstat -st
# netstat -su


4. Display PID and program names in netstat output using netstat -p

netstat -p option can be combined with any other netstat option. This will add the “PID/Program Name” to the netstat output. This is very useful while debugging to identify which program is running on a particular port.

# netstat -pt
Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        1      0 ramesh-laptop.loc:47212 192.168.185.75:www        CLOSE_WAIT  2109/firefox
tcp        0      0 ramesh-laptop.loc:52750 lax:www ESTABLISHED 2109/firefox







netstat Command in Linux

Back
The netstat command is versatile, it can help you see the channels available for network connections, interface statistics, and more. One important version of this command, netstat -r, displays routing tables that can tell you if the system knows where to send a message. 

Its functionality equivalent to the route command. When 
run on system, it's frequently run with the -n switch, to display address in numeric format. The routing table for the local system normally includes a reference to the local gateway address, coupled with the default route. 

The netstat -nr command should display the same thing. 


1. List All Ports (both listening and non listening ports)

List all ports using netstat -a
# netstat -a | more

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:30037         *:*                     LISTEN
udp        0      0 *:bootpc                *:*                              

Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     6135     /tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     5140     /var/run/acpid.socket

List all tcp ports using netstat -at
# netstat -at

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:30037         *:*                     LISTEN
tcp        0      0 localhost:ipp           *:*                     LISTEN
tcp        0      0 *:smtp                  *:*                     LISTEN
tcp6       0      0 localhost:ipp           [::]:*                  LISTEN

List all udp ports using netstat -au
# netstat -au

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
udp        0      0 *:bootpc                *:*
udp        0      0 *:49119                 *:*
udp        0      0 *:mdns                  *:*


2. List Sockets which are in Listening State

List only listening ports using netstat -l
# netstat -l

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:ipp           *:*                     LISTEN
tcp6       0      0 localhost:ipp           [::]:*                  LISTEN
udp        0      0 *:49119                 *:*

List only listening TCP Ports using netstat -lt
# netstat -lt

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:30037         *:*                     LISTEN
tcp        0      0 *:smtp                  *:*                     LISTEN
tcp6       0      0 localhost:ipp           [::]:*                  LISTEN

List only listening UDP Ports using netstat -lu
# netstat -lu

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
udp        0      0 *:49119                 *:*
udp        0      0 *:mdns                  *:*

List only the listening UNIX Ports using netstat -lx
# netstat -lx

Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     6294     private/maildrop
unix  2      [ ACC ]     STREAM     LISTENING     6203     public/cleanup
unix  2      [ ACC ]     STREAM     LISTENING     6302     private/ifmail
unix  2      [ ACC ]     STREAM     LISTENING     6306     private/bsmtp


3. Show the statistics for each protocol

Show statistics for all ports using netstat -s
# netstat -s

Ip:
    11150 total packets received
    1 with invalid addresses
    0 forwarded
    0 incoming packets discarded
    11149 incoming packets delivered
    11635 requests sent out

Icmp:
    0 ICMP messages received
    0 input ICMP message failed.

Tcp:
    582 active connections openings
    2 failed connection attempts
    25 connection resets received

Udp:
    1183 packets received
    4 packets to unknown port received.
.....
Show statistics for TCP (or) UDP ports using netstat -st (or) -su
# netstat -st
# netstat -su


4. Display PID and program names in netstat output using netstat -p

netstat -p option can be combined with any other netstat option. This will add the “PID/Program Name” to the netstat output. This is very useful while debugging to identify which program is running on a particular port.

# netstat -pt
Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        1      0 ramesh-laptop.loc:47212 192.168.185.75:www        CLOSE_WAIT  2109/firefox
tcp        0      0 ramesh-laptop.loc:52750 lax:www ESTABLISHED 2109/firefox








arp Command in Linux

Back

The arp protocol assciates the hardware of a netwrk adapter with an IP address. The arp command displays a table of harware and IP address on the local computer. 

The arp command can help detect problems such as duplicate address on the network. Such problem may happen with improperly cloned systems. 

If needed, the arp command can be used to set or modify hardware routing tables. As hardware addresses are not routable, an arp table should be limited to the local network. Here's the arp command doing its function

# arp

Addresss                HWtype      HWaddress                 Flags Mask       Iface

192.168.122.150    ether         52:A5:CB:54:52:A2         C                      eth0


Examples

Display entry for host eris:
# arp -a eris

Set a permanent cache entry for host illuminati, whose hardware address you know:
# arp -s illuminati 00:05:23:73:e6:cf

Set an ARP proxy for host fnord using the eth0 interface's hardware address:
# arp -Ds fnord eth0 pub

Remove the fnord ARP proxy:
# arp -i eth0 -d fnord pub





ifconfig Command in Linux

Back

The ifconfig command ca display the current state of active adapters. It also can be used to assign network address and more. Run the ifconfig command by itself to reviews the active network adapters on the local system. If there seems be a missing network adapter, try the ifconfig -a command, which displays the current network adapters, whether or not they are currently active.

# ifconfig eth0

Configure a Network adapter with ifconfig

You can also use ifconfig to assign IP address information as well. For example the following command assigns the noted IP address and network mask to the eth0 (ethernet 0) network adapter.

# ifconfig eth0 192.168.122.150 netmask 255.255.255.0

The first parameter, eth0 ,tells you which interface is being configured. The next argument, 192.168.122.150, specifies the new IP address being assigned to this interface, To make sure the change worked, run the ifconfig eth0 command again to view its setting.

With the right switch ,the ifconfig command can modify a number of other settings for a selected network adapter.

Parameter                             Description

up                                        Activates the specified adapter

down                                   Deactivate the specified adapter

netmask address               Assign the address subnet mask

broadcast address             Assign the address as a broadcast address. Rarely required, since the default                                            
                                            broadcast address is standard for most current network

-arp                                     Deactivates the address resolution protocol (ARP) ,which collects network          
                                             adapter hardware address


Activate and Deactivate Network Adapters using ifconfig

It's possible to use the ifconfig command to activate and deactivate network adapters. For example, the following command deactivate and deactivate the first Ethernet adapter

# ifconfig eth0 down
# ifconfig eth0 up

ifconfig command call the appropriate configuration files and scripts in the /etc/sysconfig/network-scripts directory ,for details on how a network adapter is to be activated and deactivated.

For example, the ifup eth0 command brings up the first ethernet network adapter based on the ifcfg- eth0 configuration file and the ifcfg-eth script in the /etc/sysconfig/network-scripts directory.












ping Command in Linux

Back

The ping command allows you to test connectivity. It can be locally, within a network, and across networks on the internet. For the purpose of this section, assume your IP address is 192.168.122.50, and the gate way address on the local network is 192.168.122.1. 

If you are having a problems connecting to a network, try the following ping commands in order. 
The first step is to test the integrity on your computer

# ping 127.0.0.1
    loop-back address

Normally, ping works continuously on Linux ,you'll need to press CTRL+C to stop this command. If you need to verify the proper connection to a LAN, ping the IP address of the local network card.

# ping 192.168.122.50

If that works, ping address of another compter on your network. Then start tracing the route to the internet. ping the address for the network gateway, in this case, 192.168.122.1. 

If possible, ping the address for the network's connection to the Internet, which would be on the other side of the gateway. It may be public IP address of the LAN on the internet. Add finally, ping the address of a computer that you know is active on the internet.

You can substitute host-names such as www.google.com for a IP address. If the host-name does not work, there is likely a problem with the database of host-names and IP address ,more commonly known as ( DNS )  Domain Name Server , Berkeley Internet Name Domain ( BIND ), or nameserver .

It could also indicate the problem with the /etc/hosts configuration file.


Tools ,Commands ,Gateways in Linux

Back

There are substantial numbers of tools available to manage the TCP/TP protocol suite in Linux. The most important network management commands are :

ping

ifconfig

arp

netstat -r

route

dhclient


But these are just commands there are certain files that determine the commands that are called upon to configure networks automatically during the boot process, such commands are governed by the main network configuration service script , /etc/init.d/network .







How to define a Network with IP Address in Linux

Back

Three Key IP addresses define a network , the network address, the broadcast address, and the sub-net mask. The network address is always the first IP address in range, The broadcast is always the last address in the same range . The sub-net mask helps your computer define the difference between the two addresses. You can assign IP addresses between the network and broadcast addresses to any computer on the network .

A sub-net mask is also known as a network mask or net-mask. An example of an IPv4 net-mask is 255.255.255.0, which is class c net-mask it can also be defined by the numbers of associated bits ,24.
    192.168.122.0 / 24.

Related to networking and net-masks is the concept of the gateway. It's an IP address that defines the junction between the local network and an external network. While that gateway IP address is a part of the local network such as the public Internet. The gateway IP address is normally configured in the routing table for the local system, as defined by the route or netstat -r command.




IP Version 4 Numbers, Address Classes and Formats in Linux

Back


TCP/IP is a series of protocols organized in Layers, known as a protocol suite. It was developed for Unix and eventually as the standards for communication on the internet. With the IP Address you can organize a Network .

Every computer that communicates on a network needs its own IP Address . Some address are assigned permanently to a particular computer, these are known as static addresses.Others are leased from a DHCP server for a limited amount of time,these are also known as dynamic IP addresses.

IPv4 are organised into five different classes :

CLASSES              RANGE                                              NOTE

A                        1.1.1.1 - 126.255.255.254                  Network allowed up-to 16 million computers

B                        128.0.0.1 - 192.255.255.254              Network allowed up-to 65000 computers

C                        192.0.0.1 - 223.255.255.254              Network allowed up-to 254 computers

D                       224.0.0.1 - 239.255.255.254              Reserved for multicast

E                        240.0.0.1 - 255.255.255.254              Reserved for experimental use


Private Range of Classes 

A              10.0.0.0 - 10.255.255.255

B              172.16.0.0 - 172.31.255.255

C              192.168.0.0 - 192.168.255.255


Address Formats :

Unicast : 

A Uni-cast address is associated with a single network adapter. Route-able uni-cast address include a 48-bit network prefix, 16-bit sub-net identifier, and a 64 bit interface identifier associated with a network adapter hardware address.

Multicast :

A Multicast address is used to send a message to multiple network adapters simultaneously. The organisation of a multicast address varies .

Anycast :

 An Any-cast address is used to send a message to one of several optional network adapters. It's useful for systems with multiple backups, such as a group of web servers. Any-cast have the same basic organisation as a uni-cast address .