TCP/IP has been running on Unix boxes since the beginning
Most of the development of IP networks has been done under Unix
Unix/Linux has a complete set of neworking tools and services
The command ifconfig
(inter-face configuration)
is the main tool for examining and setting TCP/IP
parameters
Typical output is
eth0 Link encap:Ethernet HWaddr 00:1d:09:d9:de:81
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:17
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
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:240 (240.0 B) TX bytes:240 (240.0 B)
wlan0 Link encap:Ethernet HWaddr 00:1f:3c:58:82:fe
inet addr:192.168.1.11 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::21f:3cff:fe58:82fe/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:164176 errors:0 dropped:0 overruns:0 frame:0
TX packets:100974 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:224602154 (224.6 MB) TX bytes:12230003 (12.2 MB)
eth0, ... are the ethernet interfaces, lo is loopback, wlan0, ... are the wireless interfaces
Examples
ifconfig eth0 up
ifconfig eth0 192.168.1.1
ifconfig eth0 netmask 255.255.255.0
Most laptops come with wireless cards for IEEE 801.11abg
To see the wireless networks in your neighbourhood, run (as root)
iwlist wlan0 scan
The essid identifies the network. The mode is normally Master. The encryption key is on or off
Encryption is WEP (weak) or WPA (strong)
To report/set parameters on your wireless interface
use iwconfig
A typical command might be
iwconfig wlan0 essid wireless mode managed key 1234567 open
GUI tools include NetworkManager
and Wicd
Nameservers are set in the file /etc/resolv.conf
nameserver 192.168.1.1
nameserver 192.168.1.4
Fixed name assignments are set in /etc/hosts
127.0.0.1 localhost
127.0.1.1 jannote
The order of searching (hosts, then DNS) is set in
/etc/nsswitch.conf
hosts: files dns mdns4
Routing tables are manipulated by the command route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 wlan0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
default jannote.local 0.0.0.0 UG 0 0 0 wlan0
You can e.g. add routes by
route add default gw 192.168.1.254
Networking is started from the rc.d shell scripts
To stop networking
/etc/init.d/networking stop
To start networking
/etc/init.d/networking start
To restart networking
/etc/init.d/networking restart
Networking is started automatically at boot-time by the
links such as (Ubuntu)
/etc/rcS.d/S40networking
General system configuration files are in /etc/sysconfig
Network config files are in /etc/sysconfig/network-scripts
Each device (e.g. eth0) has an entry as e.g. ifcfg-eth0
This lists fixed IP address of the interface or to use DHCP, plus other properties
For a static IP address
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.0.2
NETMASK=255.255.255.0
NETWORK=192.168.0.0
BROADCAST=255.255.255.255
GATEWAY=192.168.0.1
ONBOOT=yes
For a dynamic IP address
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
These will possibly change see NetworkConfigurationCommandLine/Automatic
Network config file is /etc/network/interfaces
For a static IP address
## Or configure a static IP
auto eth0
iface eth0 inet static
address 192.168.1.14
gateway 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
For a dynamic IP address
## To configure a dynamic IP address
auto eth0
iface eth0 inet dhcp
service network-manager stop
service networking restart
/etc/NetworkManager/system-connections/*
contain Network Manager configurations. These can be set to
fixed IP address by
[ipv4] method=manual address1=66.102.11.2/24,66.102.11.1for an address of 66.102.11.2 and gateway of 66.102.11.1
There are many tools for examining the state of your network
ping
netstat
DNS tools
arp
traceroute
snort, tcpdump, wireshark
netstat - Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships
netstat -r
prints routing table
netstat -i
prints interface statistics
netstat | grep -v unix
prints active TCP
connections
lsof -i
will tell you which processes are
using the network
The simplest is host name
or
host ip-address
Obsolete is nslookup
Detailed info is given by dig
$dig www.anu.edu.au
; <<>> DiG 9.5.1-P2 <<>> www.anu.edu.au
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58843
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.anu.edu.au. IN A
;; ANSWER SECTION:
www.anu.edu.au. 137 IN A 150.203.99.8
;; Query time: 1 msec
;; SERVER: 192.232.128.56#53(192.232.128.56)
;; WHEN: Wed Apr 29 16:15:37 2009
;; MSG SIZE rcvd: 48
The distros supply NetworkManager
I used Wicd in the past
You have to enable port forwarding in the file /etc/sysctl.conf
You need the line
net.ipv4.ip_forward=1
You also need to set up your routing table properly for all the interfaces so that Linux can forward to the appropriate gateway through the right interface
Run Sun's VirtualBox rather than have to build h/w
Running LiveCD of Fedora as gateway and CDs of Damn Small Linux as two clients
Run as virtual machines with "internal networking" so I get a network with no external connections to complicate things
Fedora set up to have two NICs, the DSL clients to have one each
setenforce 0
turn off SE Linux
service iptables stop
turn off IP tables
ifconfig eth0 66.102.11.1
IP address of internal NIC
ifconfig eth1 130.56.66.1
IP address of external NIC
Edit /etc/sysctl.conf
for permanent changes, or for one-off
echo 1 > /proc/sys/net/ipv4/ip_forward
ifconfig eth0 66.102.11.2
assign a static IP address (DHCP later)
route add default gw 66.102.11.1
client needs to know it's gateway to the world
ifconfig eth0 130.56.66.2
assign an IP address e.g. static or DHCP
route add default gw 130.56.66.1
To get back again