Top

A Linux User Reference

Search tips
  • search ignores words that are less than 4 characters in length
  • searches are case insensitve
  • if a search does not return anything try it in Boolean mode then Query expansion mode by checking the appropriate radio button e.g. searching for 'cron' in just the Administration category returns nothing - presumably because the 50% threshold is reached. Boolean mode ignores this threshold so a search for 'cron' returns several hits
  • in Boolean mode preceding a word with a '+' means the result must include that word, a '-' means it must not
  • in Boolean mode '+crontab -anacron' means match articles about crontab that DO NOT mention anacron
  • to match a phrase e.g. 'manage system' check the Boolean mode radio button and enclose the phrase in quotes "some phrase ..."
  • in Query expansion mode the search context is expanded beyond the keywords you entered - relevancy of hits may well be degraded

NETWORK CONFIGURATION

Host configuration

  • Configure networking
    • This can be configured statically or via DHCP (Dynamic Host Configuration Protocol).
    • Static IP configuration is normally used for small networks with a few hosts e.g. a home network.
    • DHCP is used for larger networks with many hosts. A DHCP server allocates and distributes IP addresses to DHCP clients (along with other information).
    • Usually DHCP client programs run on boot up, as part of the network configuration and request an IP address from the/a DHCP server.
    • Depending on how the DHCP server is configured the IP address allocated to a client may vary each time the client starts up.

    For more info. on DHCP see Client DHCP configuration.

    The configuration files and scripts used to configure a host's interface(s) varies from distribution to distribution.

    Redhat, Fedora IPV4

    /etc/sysconfig/network

    NETWORKING=yes
    HOSTNAME=linux-blds.my-home-lan              # localhost.localdomain
    

    For each interface there is a configuration file - /etc/sysconfig/network-scripts/ifcfg-<interface-device-name> where <interface-device-name> can be eth0, eth1, ... lo, wlan0, ... etc.

    Sample static configuration - /etc/sysconfig/network-scripts/ifcfg-eth0

    # Use STATIC
    DEVICE=eth0
    BOOTPROTO=none
    HWADDR=00:00:EF:12:34:56
    ONBOOT=yes
    TYPE=Ethernet
    NETMASK=255.255.255.248
    IPADDR=192.168.0.2
    USERCTL=no
    IPV6INIT=no
    PEERDNS=yes
    GATEWAY=192.168.0.1
    

    Sample DHCP configuration - /etc/sysconfig/network-scripts/ifcfg-eth0

    # Use DHCP
    DEVICE=eth0
    BOOTPROTO=dhcp
    HWADDR=00:00:EF:12:34:56
    ONBOOT=yes
    

    Take an interface up, down

    # /etc/sysconfig/network-scripts/if[up|down] <interface-device-name>
                                                                         (or)
    # /etc/sysconfig/network-scripts/if[up|down]-<interface type>
    

    Where <interface type> can be ppp, ipx, eth, ipp, ... etc.

    Debian, Ubuntu IPV4

    /etc/network/interfaces

    # This is the main configuration file. 
    # 'auto' is used to identify the physical interfaces to be
    # brought up when ifup is run with the '-a' option.
    
    # DHCP
    auto lo eth0
    iface lo inet loopback
    iface eth0 inet dhcp
    
    # Static
    auto eth1
    iface eth1 inet static
    address 192.168.0.11
    netmask 255.255.255.0
    gateway 192.168.0.1
    broadcast 192.168.0.255
    
    # Virtual point-to-point
    auto eth1:1
    iface eth1:1 inet static
    address 192.168.0.15
    netmask 255.255.255.0
    endpoint 192.168.0.15
    

    Follow link for debian wireless configuration examples.

    Command line

    Configure eth0 with a static IP, broadcast and netmask

    $ sudo ifconfig eth0 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255
    $ sudo route add default gw 192.168.1.1
    

    Also add a route to the interface's network.

  • Debian zero-conf netwoking

    Zero-conf uses /etc/networks.

    (IPV4) Zero-conf enables two systems (such as laptops) to be connected via a crossover Ethernet cable and communicate to each other using IP without additional manual configuration - Zero Configuration Networking.

    On larger scale networks, with more than two hosts, MDNS (Multicast DNS) provides name-to-address translation and other DNS-like operations in the absence of a conventional DNS server. I disable this service.

    The purpose of Zero Configuration Networking is not solely to make current personal computer networking easier to use. The long-term goal is to enable the creation of entirely new kinds of networked products which would negate the inconvenience and support costs involved in setting up, configuring and maintaining a network to allow them to operate thus making the products commercially viable.

    Configuration (guess there may be some!) - /etc/networks

    # (debian) symbolic names for networks, zero-conf
    link-local  169.254.0.0
    localnet 169.254.0.0
    

    Not unusual for this file to be empty or not exist.

  • Configure a network interface
    /sbin/ifconfig

    Sets parameters and can take the interface up/down.

    ifconfig [-v] [-a] [-s] [interface]
    ifconfig interface [address [parameters]]
    
    Options:
     -a                            Display all interfaces which are currently available,
                                   even if down
     -s                            Display a short list (like netstat -i)
     -v                            More verbose for some error conditions
    
    Parameters:
     up
     down
     [-]arp                        Enable or disable ARP on this interface.
     [-]promisc                    Enable or disable promiscuous mode of the interface.
     [-]allmulti                   Enable or disable all-multicast mode.
     [-]broadcast [addr]           If the address argument is given, set the protocol 
                                   broadcast addr. Else set/clear
     [-]pointopoint [addr]         If addr argument is also given => destination address
     metric N                      Set the interface metric.
     mtu N                         Set the Maximum Transfer Unit
     netmask addr                  Set the IP network mask for this interface.
     hw class address              Set mac address
     multicast                     Set the multicast flag on the interface.
     address                       Set IP address to be assigned to this interface.
     txqueuelen length             Set the length of the transmit queue of the device.
     add addr/prefixlen            Add an IPv6 address to an interface.
     del addr/prefixlen            Remove an IPv6 address from an interface.
     tunnel aa.bb.cc.dd            Create a SIT (IPv6-in-IPv4) device, tunnel to the 
                                   given destination.
    

    Configure an interface

    # ifconfig eth0 1.2.3.4 netmask 255.255.0.0 broadcast 1.2.255.255
    # ifconfig eth0 212.232.32.1/22
    

    Set the IP address

    # ifconfig eth0 18.240.32.40
    

    Add an alias

    # ifconfig eth0 alias 132.50.40.35/24
    

    Configure Token Ring for a 4 Mbp

    # ifconfig tra0 130.180.4.1/24 speed 4
    

    Configure loopback

    # ifconfig lo0 inet 127.0.0.1 up
    

    Add mac address

    # ifconfig eth0 hw ether ab:01:23:f3:00:24
    

    Configure an IPV6 primary interface

    # ifconfig lan0 inet6 up
    

    Configure an IPV6 secondary interface

    # ifconfig lan0:1 inet6 2345::5432 up
    

    Enable tunneling and create a configured tunnel

    # ifconfig tu0 inet6 up
    # route inet6 -t add c001::/64 ::192.1.1.1l
    

    Add network addresses 40-50 to subnets 18.240.32, 18.240.33, 18.240.34, 18.240.35, 18.240.36

    # ifconfig eth0 aliaslist 132.240.32-36.40-50/24
    

    Stop eth0, delete all addresses associated with the interface, and close all TCP connections

    # ifconfig eth0 down delete abort
    

    Delete the alias address 145.92.16.2 on interface tu0 and close all

    # ifconfig eth0 -alias 145.92.16.2 abort
    

    Associate MAC address aa:01:81:43:02:11 with the alias address 145.92.16.2

    # ifconfig eth0 alias 145.92.16.2 physaddr aa:01:81:43:02:11
    

    Disassociate MAC address aa:01:81:43:02:11 from the alias address 145.92.16.2

    # ifconfig eth0 -alias 145.92.16.2 -physaddr aa:01:81:43:02:11
    

    Display the hardware and IP

    # ifconfig -v eth0
    

    Configure an interface and bring it up

    # ifconfig eth1 inet mtu 1500 address 192.168.0.3 netmask 255.255.255.252 up
    

    Take an interface down

    # ifconfig eth1 down
    

    Configure MAC address of an interface

    # ifconfig eth1 hw ether 00E0206219E4
    

    Display a short list

    # ifconfig -s
    iface   MTU   Met    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
    eth0    1500   0    15908      0      0      0    15860      0      0      0 BMRU
    eth1    1500   0        0      0      0      0       55      0      0      0 BMRU
    lo     16436   0     7673      0      0      0     7673      0      0      0 LRU
    

    Show all interfaces including those that are down

    # ifconfig -a
    eth0      Link encap:Ethernet  HWaddr 00:0F:EA:CB:7A:C4
              inet addr:81.110.239.82  Bcast:255.255.255.255  Mask:255.255.252.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1             # up
              .....
    eth1      Link encap:Ethernet  HWaddr 00:E0:20:62:19:E4
              inet addr:211.211.211.2  Bcast:211.211.211.3  Mask:255.255.255.252
              inet6 addr: fe80::2e0:20ff:fe62:19e4/64 Scope:Link
              BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1                # down
              .....
    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
              .....
    
  • Take a network interface down, up
    /sbin/ifup, ifdown
    • When an interface is taken down all routes associated with it are removed, these routes clearly need to be added when the interface is back up.
    • On RedHat, these two scripts, available at boot, handle all configuration to get an interface and its routes up and running.
    • On Debian the names vary and a more modular approach is taken - /etc/if-up.d/..., if-down.d/..., if-pre-up.d/..., if-post-down.d/...

    Used to configure (or deconfigure) network interfaces based on interface definitions in the file /etc/network/interfaces. These are basically the same script that calls 'ifconfig' and 'route' to do the configuring, deconfiguring.

    ifup   [-nv] [--no-act] [--verbose]
           [-i FILE|--interfaces=FILE] 
           [--allow CLASS] 
           -a|IFACE...
    
    ifdown [-nv] [--no-act] [--verbose] 
           [-i FILE|--interfaces=FILE] 
           [--allow CLASS] 
           -a|IFACE...
    
    Options:
     -a | --all                       'ifup' - bring up in the order listed and marked
                                      as 'auto'  in /etc/network/interfaces.
                                      'ifdown' - take down in the order listed, all 
                                      interfaces in /etc/network/interfaces.
     --force                          Force configuration/deconfiguration of interface.
     --allow=CLASS                    Only act on interfaces listed in an allow-CLASS 
                                      line in /etc/network/interfaces.
     -i FILE | --interfaces=FILE      Use alternative to /etc/network/interfaces.
     -n | --no-act                    Don't configure any interfaces or run any "up"
                                      or "down" commands.
     --no-mappings                    Don't run any mappings.
    

    Examples from the man page:

    Bring up all the interfaces defined with auto in /etc/network/interfaces

    # ifup -a
    

    Bring up interface eth0

    # ifup eth0
    

    Bring up interface eth0 as logical interface home

    # ifup eth0=home
    

    Bring down all interfaces that are currently up

    # ifdown -a
    

    View info on current state of network interfaces - /var/run/network/ifstate

    # more /var/run/network/ifstate
    lo=lo
    eth0=eth0
    

    Shows current state of network interfaces - does not include wireless interfaces.

  • System hostname

    /etc/hostname

    $ cat /etc/hostname
    mark-Lenovo-G585
                                          (or)
    $ hostname
    mark-Lenovo-G585
    

    /proc/sys/kernel/hostname

    $ cat /proc/sys/kernel/hostname
    mark-Lenovo-G585
                                          (or)
    $ sysctl kernel.hostname
    kernel.hostname = mark-Lenovo-G585
    

    Show, set a system's hostname - /bin/hostname

    • Show or set the system's host name.
    • Can't change the FQDN (as returned by 'hostname --fqdn') or the DNS domain name (as returned by 'dnsdomainname') with this command.
    hostname [options] [hostname]
    
    Common options::
     -a | --alias                 Display the alias name of the host
     -d | --domain                Display the name of the DNS domain
     -F | --file filename         Read the host name from the specified file
     -f | --fqdn | --long         Display the FQDN (Fully  Qualified  Domain  Name)
     -s | --short                 Display the short host name. The host name cut at 
                                  the first '.'
     -y | --yp | --nis            Display/Set the NIS domain name - needs root access
                                  to set a new NIS domain
    

    'Examples

    $ hostname
    ub-desktop
    
    $ hostname -d
    my-home.com
    
    $ hostname --fqdn
    ub-desktop.my-home.com
    
    $ hostname -a
    ub-desktop  devbox
    
  • Host's domain name
    • Domain names are assigned through registration by http://www.internic/net/register.php.
    • A FQDN (Fully Qualified Domain Name) consists of a short host name and the DNS domain name.
    • The FQDN is the name that the resolver returns for the host name.
    • The DNS domain name is the part after the first '.'.

    To change depends on the configuration (/etc/hosts or /etc/nsswitch.conf), if the hosts file is parsed before DNS or NIS, can change it in /etc/hosts.

    Set, display a system's NIS domain name - /bin/domainname

    Set or display the domain name, do not use to get the DNS domain name - it shows the NIS/YP domain name.

    domainname [NIS domainname]
    
    $ sysctl kernel.domainname
    kernel.domainname = (none)
    

    Show a system's DNS domain name - /bin/dnsdomainname

    Show the system's DNS domain name, only option -v for verbose.

    dnsdomainname [-v]
    
    $ dnsdomainname
    my-home.com
    
  • Name resolution using static hosts lookup table
    /etc/hosts

    Sample entries

    # Static hosts lookup table, simple mappings of IP &rarr; hostnames.  
    # Used for small local networks with few hosts where allocating and 
    # maintaining IP addresses manually is not a big issue.
    
    #Format: 
    # <IP address> <canonical_hostname> <aliases>
    
    # Sample entries
    127.0.0.1     localhost
    127.0.1.1     ub-desktop.my-home.com ub-desktop devbox   
    
    # The above entry for the loopback is a Debian specific 'fix'
    # - Gnome likes to use a consistent hostname.  If not a fqdn 
    # 'dnsdomainname' and 'hostname -d' or '--fqdn' will return nothing.
    
    192.168.0.2   ubuntu.my-home.com  ubuntu testsvr
    
    # The following lines are desirable for IPv6 capable hosts
    ::1     localhost ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
    ff02::3 ip6-allhosts
    
  • Name resolution for pre-glibc2 systems
    /etc/host.conf

    Sample entries

    # Controls name resolution for pre-glibc2 systems, in case you have an old linux system.
    
    # Sample entries
    order hosts,bind              # Check /etc/hosts first then use DNS (bind)
    multi on                      # Allow multiple IP addresses for host
    
  • Name resolution for post-glibc2 systems
    /etc/nsswitch.conf

    Sample entries

    # Controls the sources used by various system library lookup functions 
    # e.g. name resolution.  Supercedes '/etc/host.conf'
    
    # The entry '[NOTFOUND=return]' means that the search for an entry
    # should stop if the search in the previous entry turned up nothing. 
    # NB that if the search failed due to some other reason (e.g. NIS 
    # server responding) then the search continues with the next entry.
    #
    # Legal entries are:
    #       nisplus or nis+         Use NIS+ (NIS version 3)
    #       nis or yp               Use NIS (NIS version 2), also called YP
    #       dns                     Use DNS (Domain Name Service)
    #       files                   Use the local files
    #       db                      Use the local database (.db) files
    #       compat                  Use NIS on compat mode
    #       hesiod                  Use Hesiod for user lookups
    #       [NOTFOUND=return]       Stop searching if not found so far
    #
    # To use db, put the "db" in front of "files" for entries you want
    # to be looked up first in the databases.
    
    # Example:
    #passwd:    db files nisplus nis
    #shadow:    db files nisplus nis
    #group:     db files nisplus nis
    passwd:     files
    shadow:     files
    group:      files
    #hosts:     db files nisplus nis dns
    hosts:      files dns            # Use local files then DNS for hostname resolution
    
    # Example - obey only what nisplus tells us...
    #services:   nisplus [NOTFOUND=return] files
    #networks:   nisplus [NOTFOUND=return] files
    #protocols:  nisplus [NOTFOUND=return] files
    #rpc:        nisplus [NOTFOUND=return] files
    #ethers:     nisplus [NOTFOUND=return] files
    #netmasks:   nisplus [NOTFOUND=return] files
    bootparams: nisplus [NOTFOUND=return] files
    ethers:     files
    netmasks:   files
    networks:   files
    protocols:  files
    rpc:        files
    services:   files
    netgroup:   nisplus
    publickey:  nisplus
    automount:  files nisplus
    aliases:    files nisplus
    
  • DNS client configuration file
    /etc/resolv.conf

    Sample entries

    # Controls the client side of DNS. Includes IP addresses of Name Servers 
    # to use, can have a maximum of three nameservers.
    
    #search
    #sortlist
    #options
    domain my-home.com
    search my-home.com
    nameserver 192.168.0.1
    

    In this case my nameserver is my router which forwards dns requests to my ISP's dns server.

    resolv.conf options:

     nameserver      Name server IP address. Maximum of three.  Queried in the order listed.
                     If no nameserver entries default is to use the name server on local 
                     machine.
     domain          Local domain name.  If no domain entry, the domain is determined from
                     the local host name. The domain part is taken to be everything after
                     the first '.'.  If the host name does not contain a domain part, the
                     root domain is assumed.
     search          Search list for host-name lookup. Normally determined from the local
                     domain name.  Default = local domain
     sortlist        A sortlist is specified by IP address netmask pairs.
                     The netmask is optional and defaults to the natural netmask of the net.
                     Up to 10 pairs may be specified. 
                     e.g. sortlist 130.155.160.0/255.255.240.0 130.155.0.0
     options         Options allows certain internal resolver variables to be modified
                     e.g. options inet6 timeout:n attempts:n