Basic network administration tools
Many of these tools provide good information about your connection and can help you diagnose issues rather quickly. All of these commands are to be run from from a terminal session and many require root rights and path. Simply open a terminal by right clicking on the Desktop and selecting "Open Terminal" or locate the Terminal icon from the Menu. Then type su -, and press enter key (which is required after every command) to become root with root path.
Information
This is by no means a full list of commands or switches.
Users requiring a list of switches or further explanation of command should consult the man pages.
There is a wealth of knowledge on how to use and what commands do can be obtained from www.google.com/linux
Some commands will need to be performed by root.
(type su -, which will give you root status)
Networking Command | Example(s) | Details |
---|---|---|
Basic Networking Status Tools | ||
ethtool | ethtool eth0 | Show status of ethernet interface eth0 |
ethtool -i eth0 | Print the driver being used for eth0 | |
ethtool --change eth0 autoneg off speed 100 duplex full | Manually set ethernet interface speed | |
mii-tool | mii-tool eth0 | Shows connectivity between system and switch and what link speed |
ifconfig | ifconfig eth0 | Show IP address and conectivity info. for eth0 |
ping | ping 1.2.3.4 | ping host 1.2.3.4, will return replies (press ctrl+C to cancel) |
iptables | iptables -L | Print the firewall rules |
lspci | lspci | List various devices in system by name etc. |
lspci | grep -i wireless | List the brand of wireless card(s) being used by system | |
lspci | grep -i ethernet | List the brand of Ethernet card(s) being used by system | |
resolv.conf config | cat /etc/resolv.conf | View the resolv.conf file which contains DNS information |
hosts config | cat /etc/hosts | View the local DNS entries and system hostname etc. |
Wireless Tools | ||
iwconfig | iwconfig eth1 | Show status of wireless interface eth1 |
iwconfig eth1 rate 1Mb/s fixed | Manually set wireless interface speed | |
iwconfig eth1 essid linksys | Manually set the wireless network SSID to linksys | |
iwconfig eth1 enc feedfeedfe | Manually set the encryption to the 64-bit HEX key feedfeedfe | |
iwlist | iwlist scan | List wireless networks in range |
IP Address - TCP/IP Configuration Tools | ||
ifdown | ifdown eth0 | Brings down a device if running |
ifup | ifup eth0 | Brings up an interface and IP |
dhclient | dhclient eth1 | Assign an IP Address via DHCP to eth1 |
ip | ip link show | List network interfaces |
ip link set dev eth0 name wan | Rename interface eth0 to wan | |
ip link set dev eth0 up | Bring interface eth0 up (or down) | |
ip addr show | List addresses for interfaces | |
ip addr add 1.2.3.4/24 brd + dev eth0 | Add (or del) ip and mask (255.255.255.0) | |
ip route show | List routing table | |
ip route add default via 1.2.3.254 | Set default gateway to 1.2.3.254 | |
netcat | netcat | setup networking services for reading from and writing network connections (UDP/TCP) |
Hostname and IP Lookup | ||
host | host w3.ibm.com | Lookup DNS ip address for name or vice versa |
hostname | hostname -i | Lookup local ip address (equivalent to host `hostname`) |
whois | whois w3.ibm.com | Lookup whois info for hostname or ip address |
route | route -n | Show the kernel routing table. |
nslookup | nslookup w3.ibm.com | get ip or host info for a host |
traceroute | traceroute x.x.x.x | look how your messages travel to host_to_trace |
netstat | netstat -tupl | List internet services on a system (UDP and TCP) |
netstat -ntlup | List internet services listening on system | |
netstat -tup | List active connections to/from system | |
Red Hat (RHEL) and Fedora Tools | ||
network setup | setup | This starts a text based setup tool (setuptool rpm must be installed) |
system-config-network-tui | system-config-network-tui | Starts text networking config tool |
system-config-network-gui | system-config-network | With or without the -gui starts the graphical net tool |
service network | service network restart | Restarts the major networking components |
service NetworkManager | service NetworkManager restart | restarts the main networking manager |
The networking applet | nm-applet | Wireless config tool (on task tray) used to connect to wireless (and all) networks |
Ubuntu and OCDC Tools | ||
service network-manager | service network-manager restart | restarts the networking manager |
service networking | service network-manager restart | restarts the networking services |
The networking applet | nm-applet | Wireless config tool (on task tray) used to connect to wireless (and all) networks |
Windows networking (Samba) | ||
smbtree | smbtree | Find windows machines. See also findsmb |
nmblookup | nmblookup -A 1.2.3.4 | Find the windows (netbios) name associated with ip address 1.2.3.4 |
smbclient | smbclient -L windows_box | List shares on windows machine or samba server |
mount windows | mount -t smbfs -o fmask=666,guest //windows_box/share /mnt/share | Mount a windows share |
send a mssg. | echo 'message' | smbclient -M windows_box | Send popup to windows machine (off by default in XP sp2) |
Ethtool
Ethernet interface tool. Must be root or use sudo to run.
- Basic usage with now options shows status of ethernet interface:
$ ethtool eth0
Settings for eth0:
Supported link modes: 10baseT/Full
100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Link partner advertised auto-negotiation: No
Speed: 100Mb/s
Duplex: Full
Port: Twisted Pair
Auto-negotiation: on
Link detected: yes - Print the driver information for eth0:
ethtool -i eth0
driver: e1000e
version: 1.0.2-k2
firmware-version: 1.8-3
bus-info: 0000:00:19.0 - set the networking speed for eth0:
$ ethtool --change eth0 autoneg off speed 100 duplex full
mii-tool
mii-tool determines the wired card connection and can be used to change the connection rate as well. Root or sudo is required. Not automatically installed on systems.
- Check if drop is connected:
mii-tool eth0
eth0: negotiated 100baseTx-FD, link ok
ifconfig
ifconfig (as root) (/sbin/ifup to it run as a user)Display info on the network interfaces currently active (ethernet, ppp, etc). Your first ethernet should show up as eth0, second as eth1,etc, first ppp over modem as ppp0, second as ppp1, etc. The "lo" is the "loopback only" interface which should be always active. Use the options (see ifconfig --help) to configure the interfaces. Key items to look for are errors and ip address info. In the example below, the user has a home wireless connection (ath0) with a Mobility client (wc0) connection to IBM.
- Example - show what all of the configured devices are and their respective network information:
$ /sbin/ifconfig
ath0 Link encap:Ethernet HWaddr 00:05:4E:48:XX:XX
inet addr:10.10.10.102 Bcast:10.10.10.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:14230 errors:1 dropped:0 overruns:0 frame:0
TX packets:8451 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:18874080 (17.9 MiB) TX bytes:958213 (935.7 KiB)
wc0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 (
inet addr:9.164.153.237 P-t-P:9.164.153.237 Mask:255.255.248.0
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1322 Metric:1
RX packets:14139 errors:0 dropped:0 overruns:0 frame:0
TX packets:8333 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:18164462 (17.3 MiB) TX bytes:479591 (468.3 KiB) - Show the ip info for a particular device (i.e. eth0, eth1, ath0, etc.):
$ ifconfig eth0
ping
Check if you can contact another machine (give the machine's name or IP), press
- Example(s):
$ ping 9.150.4.11
PING 9.150.4.11 (9.150.4.11) 56(84) bytes of data.
64 bytes from 9.150.4.11: icmp_seq=1 ttl=55 time=73.0 ms
64 bytes from 9.150.4.11: icmp_seq=2 ttl=55 time=68.2 ms
64 bytes from 9.150.4.11: icmp_seq=3 ttl=55 time=65.7 ms
--- 9.150.4.11 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2011ms
rtt min/avg/max/mdev = 65.799/69.056/7 ms$ ping w3.ibm.com -c3
PING w3.ibm.com (9.17.137.11) 56(84) bytes of data.
64 bytes from w3.ibm.com (9.17.137.11): icmp_seq=1 ttl=241 time=60.4 ms
64 bytes from w3.ibm.com (9.17.137.11): icmp_seq=2 ttl=241 time=59.9 ms
64 bytes from w3.ibm.com (9.17.137.11): icmp_seq=3 ttl=241 time=59.5 ms
--- w3.ibm.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 59.513/59.968/60.443/0.473 ms
iptables
Check that your firewall is running with iptables -L command:
- Example (NOT RUNNING):
[root@duvel ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
- Example (RUNNING):
[root@duvel ~]# iptables -L
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT udp -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT udp -- anywhere anywhere udp dpt:isakmp
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:5900
DROP tcp -- anywhere anywhere tcp dpt:netbios-ns
DROP udp -- anywhere anywhere udp dpt:netbios-ns
DROP tcp -- anywhere anywhere tcp dpt:netbios-dgm
DROP udp -- anywhere anywhere udp dpt:netbios-dgm
DROP tcp -- anywhere anywhere tcp dpt:netbios-ssn
DROP udp -- anywhere anywhere udp dpt:netbios-ssn
DROP tcp -- anywhere anywhere tcp dpts:tcpmux:ftp-data
DROP tcp -- anywhere anywhere tcp dpt:sunrpc
prefix `FIREWALL: '
LOG udp -- anywhere anywhere limit: avg 3/min burst 5..
DROP all -- anywhere anywhere
Chain FORWARD (policy DROP)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
- Example (Starting the firewall):
[root@duvel ~]# chkconfig --level 35 iptables on
[root@duvel ~]# service iptables start
Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT: filter [ OK ]
Unloading iptables modules: [ OK ]
Applying iptables firewall rules: [ OK ]
Loading additional iptables modules: ip_conntrack_ftp [ OK ]
iwconfig
iwconfig is used to display and change the parameters of the network interface. Root or sudo access may be required.
- Show status of wireless interface eth1:
# iwconfig eth1
eth1 IEEE 802.11g ESSID:"IBM"
Mode:Managed Frequency:2.427 GHz Access Point: 00:XX:XX:C6:38:2D
Bit Rate=48 Mb/s Tx-Power=20 dBm Sensitivity=8/0
Retry limit:7 RTS thr:off Fragment thr:off
Power Management:off
Link Quality=91/100 Signal level=-39 dBm Noise level=-87 dBm
Rx invalid nwid:0 Rx invalid crypt:860 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:39 Missed beacon:8 - Manually set wireless interface speed:
# iwconfig eth1 rate 1Mb/s fixed
- Manually set the wireless network SSID to 'linksys':
# iwconfig eth1 essid linksys
- Manually set the encryption to the 64-bit HEX key 'feedfeedfe':
# iwconfig eth1 enc feedfeedfe
iwlist
iwlist is used to scan for available wireless networks and display additional information about them that is not displayed by iwconfig.
- List nearby wireless access points using the 'eth1' device:
# iwlist eth1 scan
eth1 Scan completed :
Cell 01 - Address: 00:XX:XX:XX:E6:AF
ESSID:"HOME_LINUX_ROUTER"
Protocol:IEEE 802.11bg
Mode:Master
Channel:1
Encryption key:off
Bit Rate:54 Mb/s
Quality=82/100 Signal level=-48 dBm
Extra: Last beacon: 36ms ago
ifdown and ifup
(/sbin/ifup to it run as a user) Startup a network interface.
[thesmartguy@wifitest ~]$ /sbin/ifup eth0
(/sbin/ifdown to run it as a user). Shut down the network interface.
[thesmartguy@wifitest ~]$ /sbin/ifdown eth0
dhclient
dhclient will request dhcp (automatically assigned IP address etc.) on a dhcp enabled campus or home router system. This happens even if the system has a static ip already assigned and configured. Root or sudo access is required.
- Assign an IP Address via DHCP to eth0:
# dhclient eth0
Internet Systems Consortium DHCP Client V3.1.3
Copyright 2004-2009 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/eth0/00:27:13:68:11:78
Sending on LPF/eth0/00:27:13:68:11:78
Sending on Socket/fallback
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 4
DHCPOFFER of 192.168.1.2 from 192.168.1.1
DHCPREQUEST of 192.168.1.2 on eth0 to 255.255.255.255 port 67
DHCPACK of 192.168.1.2 from 192.168.1.1
bound to 192.168.1.2 -- renewal in 33325 seconds.
ip
ip is one of the more 'modern' tools for viewing and changing IP address settings. Using ip is recommended
- Rename interface name from eth0 to 'wan':
ip link set dev eth0 name wan
- Bring interface eth0 up (or down):
ip link set dev eth0 up
- List addresses for interfaces:
# ip addr show
1: eth0:mtu 1500 qdisc pfifo_fast state UP qlen 100
link/ether 00:XX:XX:68:11:78 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.2/24 brd 192.168.1.255 scope global eth0
inet6 fe80::227:13ff:fe68:1178/64 scope link
valid_lft forever preferred_lft forever - Configure (or del) ip (ex. 9.82.11.11) and mask (255.255.255.0) in one step:
ip addr add 9.82.11.11/24 brd + dev eth0
- List routing table:
ip route show
- Set default gateway to 9.82.11.1:
ip route add default via 9.82.11.1
netcat
Netcat (or nc) is a computer networking service for reading from and writing network connections using TCP or UDP. Netcat is a "back-end" device that can be used easily by other programs and scripts.
- Opening a raw connection to port 25 (like telnet)
nc mail.server.net 25
- Proxy - in example, port 1234 represents the request and redirects (as a server) to port 80 (google.com)
nc -l -p 1234 | nc www.google.com 80
- Making any process a server - bash
nc -l -p 1234 -e /bin/bash
- Port Forwarding or Port Mapping
nc -l -p portx -c ' nc -l -p porty'
nc -l -p portx -c ' nc host2 porty'
nc -l -p portx -c ' nc -u -l -p porty'
nc host1 portx -c ' nc host2 porty'
nc -u -l -p portx -c ' nc -u -l -p porty'
route
route -n Show the kernel routing table.
- Example:
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
9.150.15.128 0.0.0.0 255.255.255.128 U 0 0 0 eth0
0.0.0.0 9.150.15.129 0.0.0.0 UG 0 0 0 eth0
nslookup
Query your default domain name server (DNS) for an Internet name (or IP number) host_to_find. This way you can check if your DNS works. You can also find out the name of the host of which you only know the IP number.
- lookup an ip address, does it exist as a DNS record (i.e. is it real or local to computer) ?
$ nslookup 9.150.4.11
Server: 9.64.162.21
Address: 9.64.162.21#53
11.4.150.9.in-addr.arpa name = linuxsrv01.greenock.uk.ibm.com.
3.075/3.033 ms
- Do the same for the hostname of a machine (i.e. does the machine have a real host or is a locally named computer?
[root@duvel ~]# nslookup bluex.fishkill.ibm.com
Server: 9.0.2.1
Address: 9.0.2.1#53
Name: bluex.fishkill.ibm.com
Address: 9.62.11.80
traceroute
Have a look how you messages travel to host_to_trace (which is either a host name or IP number).
- Example:
$ traceroute 9.150.4.11
traceroute to 9.150.4.11 (9.150.4.11), 30 hops max, 40 byte packets
1 ICON-9-164-152-1.megacenter.de.ibm.com (9.164.152.1) 64 ms
2 dem-aag-id-inta.megacenter.de.ibm.com (9.149.245.3) 77 ms
3 9.149.254.153 (9.149.254.153) 78 ms
4 9.149.130.21 (9.149.130.21) 86 ms
5 DEIBP9EH1-01R.p9.emea.ibm.com (9.149.250.50) 92 ms
6 9.64.130.6 (9.64.130.6) 93 ms
7 IBP9GBRGK01A7300R01-POS3-0-16.wan.ibm.com (9.64.132.189) 90 ms
8 GNKB7206R28F1-256.greenock.uk.ibm.com (9.134.129.3) 98 ms
9 9.150.1.58 (9.150.1.58) 106 ms
10 linuxsrv01.greenock.uk.ibm.com (9.150.4.11) 119 ms
netstat
see what services are waiting for network traffic. It's a good way to see what ports you have running on your system. Note, these are the services running on your system but the firewall could still be limiting them from incoming traffic which is generally a good thing.
- Active Internet connections (only servers):
# netstat -ntlp
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 2222/hpiod
tcp 0 0 0.0.0.0:34984 0.0.0.0:* LISTEN 2292/java
tcp 0 0 0.0.0.0:53387 0.0.0.0:* LISTEN 5247/notes2w
tcp 0 0 0.0.0.0:21100 0.0.0.0:* LISTEN 2292/java
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1828/portmap
tcp 0 0 127.0.0.1:8979 0.0.0.0:* LISTEN 3160/wcstatusd
tcp 0 0 127.0.0.1:21235 0.0.0.0:* LISTEN 2292/java
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2255/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2239/cupsd
tcp 0 0 127.0.0.1:21018 0.0.0.0:* LISTEN 2292/java
tcp 0 0 0.0.0.0:51579 0.0.0.0:* LISTEN 5247/notes2w
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN 2227/python
tcp 0 0 0.0.0.0:767 0.0.0.0:* LISTEN 1857/rpc.statd
- List active connections to/from system:
netstat -tup
0 comments
Post a Comment