Monday, March 24, 2014

Networking in Linux

Linux TCP/IP Network configuration files

FileDescription
/etc/resolve.confList DNS servers for internet domain name resolution.
Manual page for: /etc/resolv.conf
/etc/hostsLists hosts to be resolved locally (not by DNS).
Manual page for: /etc/hosts
/etc/nsswitch.confList order of host name search. Typically look at local files, then NIS server, then DNSserver.
Manual page for: /etc/nsswitch.conf
Red Hat/Fedora/CentOS: /etc/sysconfig/networkSpecify network configuration. eg. Static IPDHCPNIS, etc.
Red Hat/Fedora/CentOS: /etc/sysconfig/network-scripts/ifcfg-deviceSpecify TCP network information.
Ubuntu/Debian: /etc/network/interfacesSpecify network configuration and devices. eg. Static IP and info, DHCP, etc.

  • DOMAIN RESOLUTION CONFIGURATION FILES

  • File: /etc/resolv.conf - host name resolver configuration file
    search name-of-domain.com  - Name of your domain or ISP's domain if using their name server
    nameserver XXX.XXX.XXX.XXX - IP address of primary name server
    nameserver XXX.XXX.XXX.XXX - IP address of secondary name server
                  
    This configures Linux so that it knows which DNS server will be resolving domain names into IP addresses. If using DHCP client, this will automatically be sent to you by the ISP and loaded into this file as part of the DHCP protocol. If using a static IP address, ask the ISP or check another machine on your network.
    Red Hat/Fedora GUI: /usr/sbin/system-config-network (select tab "DNS").
  • File: /etc/hosts - locally resolve node names to IP addresses
    127.0.0.1         your-node-name.your-domain.com  localhost.localdomain  localhost 
    XXX.XXX.XXX.XXX   node-name
                  
    Note when adding hosts to this file, place the fully qualified name first. (It helps sendmail identify your server correctly) i.e.:
        XXX.XXX.XXX.XXX  superserver.yolinux.com  superserver
        
    This informs Linux of local systems on the network which are not handled by the DNS server. (or for all systems in your LAN if you are not using DNS or NIS)The file format for the hosts file is specified by RFC 952.
    Red Hat/Fedora configuration GUI: /usr/sbin/system-config-network (select tab "Hosts").
  • File: /etc/nsswitch.conf - System Databases and Name Service Switch configuration file
    hosts:   files dns nisplus nis
              
    This example tells Linux to first resolve a host name by looking at the local hosts file(/etc/hosts), then if the name is not found look to your DNS server as defined by/etc/resolv.conf and if not found there look to your NIS server.In the past this file has had the following names: /etc/nsswitch.conf, /etc/svc.conf, /etc/netsvc.conf, ... depending on the distribution.

Assigning IP addresses


Computers may be assigned a static IP address or assigned one dynamically. Typically a server will require a static IP while a workstation will use DHCP (dynamic IP assignment). The Linux server requires a static IP so that those who wish to use its resources can find the system. It is more easily found if the IP address does not change and is static. This is not important for the Linux client workstation and thus it is easier to use an automated Dynamic Host Configuration Protocol (DHCP) for IP address assignment.

Static IP address assignment:

Choose one of the following methods:
  • Command Line:
        /sbin/ifconfig eth0 192.168.10.12 netmask 255.255.255.0 broadcast 192.168.10.255
        
    Network address by convention would be the lowest: 192.168.10.0
    Broadcast address by convention would be the highest: 192.168.10.255
    The gateway can be anything, but following convention: 192.168.10.1Note: the highest and lowest addresses are based on the netmask. The previous example is based on a netmask of 255.255.255.0
  • Red Hat / Fedora GUI tools:
    • /usr/bin/neat Gnome GUI network administration tool. Handles all interfaces. Configure for Static IP or DHCP client.
      (First available with Red Hat 7.2.)
    • /usr/bin/netcfg (Handles all interfaces) (last available in Red Hat 7.1)
  • Red Hat / Fedora Console tools:
    • /usr/sbin/system-config-network-tui (Text User Interface)
    • /usr/sbin/netconfig (Only seems to work for the first network interface eth0 but not eth1,...)
  • Directly edit configuration files/scripts. See format below.
The ifconfig command does NOT store this information permanently. Upon reboot this information is lost. Manually add the network configuration to /etc/sysconfig/network-scripts/ifcfg-eth0 (Red Hat/Fedora/CentOS) for the first NIC, ifcfg-eth1 for the second, etc, or /etc/network/interfaces (Ubuntu) as shown below. Any other commands you may want to add to the system boot sequence can be added to the end of the file /etc/rc.d/rc.local. The commands netcfg and netconfig make permanent changes to system network configuration files located in /etc/sysconfig/network-scripts/, so that this information is retained and used upon system boot.

Static and Dynamic IP Configuration

Static IP address configuration:
DEVICE=eth0
BOOTPROTO=static
BROADCAST=XXX.XXX.XXX.255
IPADDR=XXX.XXX.XXX.XXX
NETMASK=255.255.255.0
NETWORK=XXX.XXX.XXX.0
ONBOOT=yes                       - Will activate upon system boot
                    
RHEL4/FC3 additions:
  • TYPE=Ethernet
  • HWADDR=XX:XX:XX:XX:XX:XX
  • GATEWAY=XXX.XXX.XXX.XXX
OR for DHCP client configuration:
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
                    


Changing the hostname


One may also want to check the file /etc/hosts for an entry using the system name which allows the system to be self aware.The hostname may be changed at runtime using the command: sysctl -w kernel.hostname="superserver"

4 comments:

  1. Source: http://www.yolinux.com/

    ReplyDelete
  2. Q: - What is round robin DNS?
    Round robin DNS is usually used for balancing the load of geographically distributed Web servers. For example, a company has one domain name and three identical home pages residing on three servers with three different IP addresses. When one user accesses the home page it will be sent to the first IP address. The second user who accesses the home page will be sent to the next IP address, and the third user will be sent to the third IP address. In each case, once the IP address is given out, it goes to the end of the list. The fourth user, therefore, will be sent to the first IP address, and so forth.
    Q: - What is Name Server?
    A name server keeps information for the translation of domain names to IP addresses and IP addresses to domain names. The name server is a program that performs the translation at the request of a resolver or another name server.
    Q: - What is Primary name server or primary master server?
    Primary name server/primary master is the main data source for the zone. It is the authoritative server for the zone. This server acquires data about its zone from databases saved on a local disk. The primary server must be published as an authoritative name server for the domain in the SOA resource record, while the primary master server does not need to be published.
    Q: - What is Secondary name server/slave name server?
    Secondary name server/slave name server acquires data about the zone by copying the data from the primary name server (respectively from the master server) at regular time intervals. It makes no sense to edit these databases on the secondary name servers, although they are saved on the local server disk because they will be rewritten during further copying.
    Q: - what is Root name server?
    Root name server is an authoritative name server for the root domain (for the dot). Each root name server is a primary server, which differentiates it from other name servers.
    Q: - what is Stealth name server?
    Stealth name server is a secret server. This type of name server is not published anywhere. It is only known to the servers that have its IP address statically listed in their configuration. It is an authoritative server. It acquires the data for the zone with the help of a zone transfer. It can be the main server for the zone. Stealth servers can be used as a local backup if the local servers are unavailable.
    Q: - What do you mean by "Resource Records"?

    Information on domain names and their IP addresses, as well as all the other information distributed via DNS is stored in the memory of name servers as Resource Records (RR).
    Q: - Explain "TTL"?

    Time to live. A 32-bit number indicating the time the particular RR can be kept valid in a server cache. When this time expires, the record has to be considered invalid. The value 0 keeps nonauthoritative servers from saving the RR to their cache memory.
    Q: - Tell me 5 Types of DNS records?

    A, NS, CNAME, SOA, PTR, MX.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Basic differences between TCP/IP and UDP.

    TCP/IP
    Transmission Control Protocol
    It is connection Oriented
    Reliable
    TCP Acknowledgement will be sent/received
    Slow Communication
    Protocol Number for TCP is 6
    HTTP, FTP, SMTP uses TCP

    UDP
    User Datagram Protocol
    Connectionless
    Non-reliable
    No Acknowledgement for UDP
    Faster Communication
    Protocol Number for UDP is 17
    DNS, DHCP uses UDP

    ReplyDelete