Networking Linux

hostname

Host/Domain Name and IP Address

To display the host name, domain name or IP address of your machine, the command hostname is used. Each machine has a host name which is associated with a domain name. Each machine also has a unique IP address. IP addresses are assigned to each network node or connection point.  An easy way to understand host and domain names is to compare them to a families first and last name, where the host name is the different first name for each family member and the domain name is the family’s last name. Think of the IP address as a unique phone number for each family member.

Example network configuration:

Equipment Domain Name Host Name IP Address
Server yourdomain.com linux 192.168.1.1
Workstation #1 yourdomain.com joe 192.168.1.10
Workstation #2 yourdomain.com fred 192.168.1.11
Networked Printer yourdomain.com hplaser 192.168.1.50
Router yourdomain.com newyork 192.168.1.51
Options What it does
-d Display domain name
-f Display fully qualified name
-i Display IP address associated with network card on the current machine

Examples: The results listed below are based on the examples given above.

Examples What it does
hostname With no options, displays the machine’s host name – linux
hostname -d Display the domain name the machine belongs to – ourdomain.com
hostname -f Display the fully qualified host and domain name – linux.ourdomain.com
hostname -i Display the IP address for the current machine – 192.168.1.1

top of page


ping – Test network connection

To test your network connection with another network device, the command ping is used. It sends packets of information to the user-defined source. If the packets are received, the destination device sends packets back. Ping can be used for two purposes.

  1. To ensure that a network connection can be established.
  2. Timing information as to the speed of the connection.

Command: ping domain name or IP address

(IP address are always in the format of xxx.xxx.xxx.xxx)

If you start ping with a domain name, it will display the actual IP address assigned to the domain name. The domain name can be entered with or without the typical starting ‘www’

Examples:

ping www.ahinc.com - responds back with...
PING www.ahinc.com (209.218.236.72): 56 data bytes
64 bytes from 209.218.236.72: icmp_seq=0 ttl=117 time=69.9 ms
64 bytes from 209.218.236.72: icmp_seq=1 ttl=117 time=69.9 ms
64 bytes from 209.218.236.72: icmp_seq=2 ttl=117 time=71.0 ms
64 bytes from 209.218.236.72: icmp_seq=3 ttl=117 time=69.4 ms
64 bytes from 209.218.236.72: icmp_seq=4 ttl=117 time=74.6 ms
--- www.ahinc.com ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 69.4/70.9/74.6 ms

(Note: Use Control-C to stop the test)

ping 192.168.1.1 - responds back with...
PING 192.168.1.1 (192.168.1.1): 56 data bytes
64 bytes from 192.168.1.1: icmp_seq=0 ttl=64 time=0.2 ms
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.1 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.1 ms
--- 192.168.1.1 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.1/0.1/0.2 ms

(Note: Use Control-C to stop the test)

Note the difference in turn around time for the above examples. The first ping sent packets over the internet with an average of 70.9ms. The second ping was to a local device with an average of only .1 ms.

top of page


ifconfig – View network configuration

The command ifconfig (interface config) can be used to actually configure the network adapter. But for most purposes, and to keep you out of trouble, we are only going to use this command to display the current network adapter configuration. It is handy to determine if you are getting transmit (TX) or receive (RX) errors.

ifconfig
Displays…

lo Link encap:Local Loopback
inet addr:127.0.0.1 Bcast:127.255.255.255 Mask:255.0.0.0
UP BROADCAST LOOPBACK RUNNING MTU:3584 Metric:1
RX packets:292320 errors:0 dropped:0 overruns:0
TX packets:292320 errors:0 dropped:0 overruns:0

eth0 Link encap:10Mbps Ethernet HWaddr 00:60:94:57:D3:55
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7820768 errors:3465 dropped:0 overruns:0
TX packets:8643039 errors:0 dropped:0 overruns:0
Interrupt:14 Base address:0x5180

eth1 Link encap:10Mbps Ethernet HWaddr 00:C0:F0:1F:55:26
inet addr:216.227.29.113 Bcast:216.227.29.115 Mask:255.255.255.252
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1224415 errors:0 dropped:0 overruns:0
TX packets:208329320 errors:0 dropped:0 overruns:0
Interrupt:11 Base address:0x5100

The above results represent a system that has two NICS (network interface cards eth0 and eth1) and the standard loopback interface. (lo)
top of page


netstat network connections, routing tables, interface statistics

The command netstat displays information for all active sockets, including the port numbers associated with each type of network service.

Options What it does
-o Displays some additional information on networking timers
-a Display all sockets, including the listening server sockets
-r Displays kernel routing tables
-i Display a table of all (or the specified iface) networking interfaces
-M Display a list of all masqueraded sessions
-v Tell the user what is going on by being verbose
-e Additional information

Examples for netstat

Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 linux.ahinc:netbios-ssn nt:1118 ESTABLISHED
tcp 0 0 linux.ahinc:netbios-ssn lorie:1025 ESTABLISHED
tcp 0 0 linux.ahinc:netbios-ssn roger:1025 ESTABLISHED
tcp 0 0 linux.ahinc:netbios-ssn omni:1825 ESTABLISHED
tcp 0 0 linux.ahinc.com:27381 ferret.toledolink.:6667 ESTABLISHED
tcp 0 126 linux.ahinc.com:telnet omni:1829 ESTABLISHED
Proto Recv-Q Send-Q Local Address Foreign Address
udp 0 0 localhost:domain *:*
udp 0 0 linux.ahinc.com:domain *:*
udp 0 0 linux.ahinc.com:domain *:*
udp 0 0 linux.ahinc.:netbios-ns *:*
udp 0 0 linux.ahinc:netbios-dgm *:*
udp 0 0 linux.ahinc.:netbios-ns *:*
udp 0 0 linux.ahinc:netbios-dgm *:*
udp 0 0 localhost:1421 *:*
udp 0 0 localhost:1691 *:*
udp 0 0 localhost:1803 *:*
udp 0 0 localhost:1076 *:*

Explanation of above….

Active Internet connections (TCP, UDP, RAW) – Socket information

  • Proto – Protocol (tcp, udp, raw)
  • Recv-Q – Count of bytes not copied by the user program connected
    to this socket.
  • Send-Q – Count of bytes not acknowledged by the remote host.
  • Local Address – Local address (local hostname) and port number of socket. Unless the -n switch is given, the socket address is resolved to its canonical hostname, and the port number is translated into the corresponding service name.
  • Foreign Address – Remote address (remote hostname) and port number of socket. As with the local address:port, the -n switch turns off hostname and service name resolution.
  • State – Socket state. Since there are no states in RAW and usually no states used in UDP, this row may be left blank.
    • ESTABLISHED – Established connection
    • SYN_SENT – Attempting to establish a connection.
    • SYN_RECV – Connection is being initialized.
    • FIN_WAIT1 FIN_WAIT2 – Connection is closed, and waiting for a shutdown from the remote end.
    • TIME_WAIT – Waiting after close for remote shutdown retransmission.
    • CLOSED – Not being used.
    • CLOSE_WAIT – The remote end has shut down, waiting to close. LAST_ACK
      – The remote end shut down and closed. Waiting for acknowledgement.
    • LISTEN – Listening for incoming connections. Those sockets
      are only displayed if the -a switch is set.
    • CLOSING – Shut down but we still don’t have all data sent.

Active
UNIX domain sockets (w/o servers)

Proto RefCnt Flags Type State I-Node Path
unix 2 [ ] STREAM CONNECTED 589
unix 2 [ ] STREAM 590 /dev/log
unix 2 [ ] STREAM CONNECTED 686
unix 2 [ ] STREAM 687 /dev/log
unix 2 [ ] STREAM CONNECTED 720
unix 2 [ ] STREAM 721 /dev/log
unix 2 [ ] STREAM CONNECTED 760
unix 2 [ ] STREAM 761 /dev/log
unix 2 [ ] STREAM CONNECTED 808
unix 2 [ ] STREAM 809 /dev/log
unix 2 [ ] STREAM CONNECTED 9898058
unix 2 [ ] STREAM 9898059 /dev/log

Explanation of above…

Active UNIX domain Sockets

  • Proto – Protocol (usually unix) used
  • RefCnt – Reference count (i.e. attached processes via this socket).
  • Flags – Flags displayed is SO_ACCEPTON (displayed as ACC), SO_WAITDATA
    (W) or SO_NOSPACE (N). SO_ACCECPTON is used on unconnected sockets if their corresponding processes are waiting for a connect request. The other flags are not of normal interest.
  • Type – Types of socket access:
    • DGRAM – Used in Datagram (connectionless) mode.
    • STREAM – Stream (connection) socket.
    • RAW – Raw socket.
    • RDM – Reliably-delivered messages.
    • SEQPACKET – Sequential packet socket.
    • PACKET – RAW –  Interface access socket
  • State:
    • FREE – Not allocated
    • LISTENING – Listening for a connection request. Those sockets
      are only displayed if the -a switch is set.
    • CONNECTING – About to establish a connection.
    • CONNECTED – Connected.
    • DISCONNECTING – Disconnecting.
    • (empty) – Not connected to another socket.

netstat -i

Kernel Interface table

Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flags
lo 3584 0 292400 0 0 0 292400 0 0 0 BLRU
eth0 1500 0 7835216 3538 0 0 8656416 0 0 0 BRU
eth1 1500 0 1226077 0 0 0 208330964 0 0 0 BRU

 

netstat -M

IP masquerading entries

prot expire source destination ports
tcp 14:52.40 empac.ahinc.com dalnet.digital-web.net 2145 -> 6667 (62134)

netstat -r

Kernel IP routing table

Destination Gateway Genmask Flags MSS Window irtt Iface
dsl-216-227-29- * 255.255.255.252 U 1500 0 0 eth1
192.168.1.0 * 255.255.255.0 U 1500 0 0 eth0
loopback * 255.0.0.0 U 3584 0 0 lo
default dsl-216-227-29- 0.0.0.0 UG 1500 0 0 eth1

top of page


nslookup
(DNS) Domain Name Servers

To find all of the IP addresses for a given domain name, the command nslookup is used. You must have a connection to the internet for this utility to be useful.

Command: nslookup <domain name>
Examples:

nslookup hp.com – Displays…

Server: localhost
Address: 127.0.0.1
Name: hp.com
Addresses: 192.151.52.13, 192.151.52.10, 192.151.11.13, 192.151.11.32
nslookup www.hp.com – Displays…

Server: localhost
Address: 127.0.0.1
Name: www.hp.com
Addresses: 192.151.52.10, 192.151.11.40, 192.151.11.32, 192.151.11.13
192.151.52.187, 192.151.52.13

top of page


telnet
Communicate with another host

To login into a another computer, the command telnet is used. You need at least 3 pieces of information to perform a telnet session:

  • remote host IP address
  • login name
  • password

The standard telnet supplied with Linux only emulates a vt or ANSI type terminal.
Examples:
telnet ahinc.com
telnet 192.168.1.1

top of page


traceroute – routing steps

A handy utility to view the number of hops (connection points) and response time to get to a remote system or web site is traceroute. Again you need an Internet connection to make use of this tool.

Command: traceroute<domainname> -or <IP address>
Examples:

traceroute www.yahoo.com – Displays…

traceroute: Warning: www.yahoo.com has multiple addresses; using 216.32.74.53
traceroute to www.yahoo.akadns.net (216.32.74.53), 30 hops max, 40 byte packets
1 dsl-216-227-29-114.chi.interchangedsl.com (216.227.29.114) 0.985 ms 0.931 ms 0.931 ms
2 route-216-227-1-1.telocity.com (216.227.1.1) 7.823 ms 6.668 ms 6.887 ms
3 fe1-2-core1.chi.tlct.net (216.227.0.129) 7.229 ms 7.385 ms 7.086 ms
4 pos8-1-hfr2.den.tlct.net (216.227.126.5) 124.301 ms 54.351 ms 96.082 ms
5 fe1-2-core1.chi.tlct.net (216.227.0.129) 97.748 ms 112.442 ms 87.024 ms
6 fe0-0-nap1.chi.tlct.net (216.227.126.98) 100.293 ms 52.982 ms 53.425 ms
7 aads-nap.exodus.net (206.220.243.63) 55.378 ms 97.531 ms 99.953 ms
8 bbr01-g4-0.okbr01.exodus.net (216.34.183.97) 54.298 ms 104.866 ms 98.25 2ms
9 bbr02-p6-0.jrcy01.exodus.net (216.32.132.110) 120.769 ms 88.920 ms 100.35 5 ms
10 bbr01-p5-0.stng01.exodus.net (209.185.9.98) 105.994 ms 93.372 ms 101.849ms
11 dcr04-g9-0.stng01.exodus.net (216.33.96.146) 78.310 ms 96.501 ms 99.288 ms
12 216.33.98.19 (216.33.98.19) 101.885 ms 89.226 ms 97.608 ms
13 216.35.210.126 (216.35.210.126) 102.190 ms 79.119 ms 115.664 ms
14 www4.dcx.yahoo.com (216.32.74.53) 99.589 ms 93.858 ms 99.972 ms

top of page


finger – View user information

Displays a user’s login name, real name, terminal name and write status (as a “*” after the terminal name if write permission is denied), idle time, login time.

finger roger – Displays…

Login: roger Name: Roger Petersen
Directory: /home/roger Shell: /bin/bash
On since Sun Jun 11 12:21 (CDT) on ttyp0 from omni
1 second idle
No mail.
No Plan.

top of page


ppp Configuration

The following provides brief instuctions on setting up Linux to operate as a remote network server connection using ppp.

Make sure the packages mgetty, pap and rzsz are installed.

This examples assumes

  • Your modem is connected to ttyS0
  • There is a link from /dev/ttyS0 to /dev/modem
File Configuration
/etc/inittab You need to modify the modem entry to start with run levels 3 and 5 mo:35:respawn/usr/sbin/mgetty -D -s38400 /dev/modem
/etc/ppp/options.ttyS0 This file needs to be created. The first entry represents the IP address for the ppp0 address on the server side.
The second entry represents the IP to use for the remote
IP address. 192.168.1.180:192.168.110
/etc/mgetty+sendfax/login.config To allow pap authentication, add this line (all on one line)… /AutoPPP/ – a_ppp /usr/sbin/pppd auth login -chap +pap file /etc/ppp/options.tty
/etc/ppp/pap-secrets Comment out all 0 CONNECTIONS and add the following line(s) for login name(s) you are going to allow. substitute TAB for spaces) loginname * “” * sam * “” *

Windows Set-up
In order for the standard Windows Dialup Network program to login automatically, create the following script on your Windows machine.

proc main
  transmit "^M"
  waitfor "ogin:"
  if $SUCCESS then
    transmit $USERID
    transmit "^M"
    waitfor "ssword:"
    if $SUCCESS then
      transmit $PASSWORD
      transmit "^M"
    endif
  endif
endproc

You can save this file anywhere and name it whatever you want. Let’s assume you save it as C:\windows\login.scp In the properties of your dialin script, click on the Scripting tab and enter the full path and file name. (i.e. :\windows\login.scp)

top of page


NFS

To use NFS you need to have portmapper running. Otherwise you will get messages about not being to lock/unlock files.In addition you also need rpc.statd and rpc.lock.

To mount automatically at boot time, edit the /etc/fstab

top of page