08

08/10

Linux Network Configuration for home Users

8:59 pm by Admir. Postuar tek: Linux,Network

The Tools – net-tools VS iproute2

There are 2 generic packages that do all-most the same thing’s.

  • net-tools which include:
  • ifconfig,
  • nameif
  • plipconfig
  • rarp
  • route
  • slattach
  • ipmaddr
  • iptunnel
  • mii-tool
  • netstat
  • hostname

It is older compared to iproute2 packages but it is still used.

  • iproute2 includes:
  • rtmon
  • ip
  • netbug
  • rtacct
  • ss
  • lnstat
  • nstat
  • cbq
  • tc
  • arpd

Net-tools have been great till 2.4/2.4/2.6 kernel shows up with completely new network design. They work just fine but, for some tasks, they show some strange behavior and are very outdated for complicated tasks / advanced routing. Sow, we are going to use generally iproute2.

Settings things UP {eth0|wlan0}

We just started the PC, and want to be online, we have a router in my case just a linksys-cisco, and we are going to use /24 CIDR with the router at 192.168.1.1 (default).

  • Dealing with our “links” – interfaces bringing them up and down

This is the easy way, for home networks with 1-2 box’s connected and this is the “plug’n play” way. First we bring the interfaces up :

#ip link set eth0 down   ==> Same as ifconfig eth0 down
#ip link set wlan0 down  ==> Same as ifconfig wlan0 down

Now, the 2 interfaces are down, and we can check this with

#ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
   link/ether 00:11:60:0a:ed:c6 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN qlen 1000
   link/ether 00:11:de:bc:ad:e2 brd ff:ff:ff:ff:ff:ff

We can notice that the lo interface (LoopBack is UP) instead of eth0 and wlan0 , there is no UP at <BROADCAST,MULTICAST> the “state DOWN” tells the state of the connection and not the state of the our wireless card or ethernet card.

Now we want them up, because we want to connect to our router.

#ip link set eth0 up; ip link set wlan0 up
OR
#ifconfig eth0 up; ifconfig wlan0 up

We want to see if the interfaces are up and we check with

#ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
   link/ether 00:1d:60:0f:eb:c6 brd ff:ff:ff:ff:ff:ff
3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
   link/ether 00:18:de:c7:a0:6b brd ff:ff:ff:ff:ff:ff
  • Static DHCP or Dynamic DHCP?

Now that they are up, we have 2 ways of doing things with this interfaces,

  • Static DHCP — we have to specify the IP, the Netmask, the Default Gateway
  • Dynamic DHCP — we dont have to specify nothing

Sow, why Static DHCP? – In large network’s it’s all most a default type of configuration, because lets say we have a postgres sql server at 192.168.1.201 and 3 servers A,B,C with different ip address connecting to him for getting reading\writing data. Some – day, we have a problem with him, or just want to restart and we restart him, but now we have a big problem because the DHCP gives him 192.168.1.13 as ip address and the things goes mad. The same happens if we apply for different service that need other service etc. Why Dynamic DHCP ? If we are at home, and friends come to my house, i don’t want to set they ip manually so just plug & play.

Configuring eth0 with Automatic IP (DHCP)

We just connect the cable and we are just fine :) NOTE: If you have no dhcp client running you must run the client for getting your connection setting from the DHCP server running on the server. In my case, befor connecting the cable:

  • No – ip | No connection UP

WARNING: NO-CARRIER,BROADCAST,MULTICAST,UP ==>> Hardware Interface UP state DOWN ==>> Connection is Down

#ip addr show eth0
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
   link/ether 00:1d:60:0f:eb:c6 brd ff:ff:ff:ff:ff:ff
   inet6 fe80::21d:60ff:fe0f:ebc6/64 scope link
  • Routing table clear, no router:
#ip route show
[root@darkinet arditi]#

Routing table is empty

Or we can use:

#route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

Now i connect the ethernet cable on my laptop and on the router, the result is the same. Nothing happens, and this is because I’m on arch linux and all is manual , so I have to contact the dhcp server for getting the data and in my case:

# dhcpcd eth0
dhcpcd: version 5.2.2 starting
dhcpcd: eth0: rebinding lease of 192.168.1.100
dhcpcd: eth0: acknowledged 192.168.1.100 from 192.168.1.1
dhcpcd: eth0: checking for 192.168.1.100
dhcpcd: eth0: leased 192.168.1.100 for 86400 seconds
dhcpcd: forking to background

Now for being shore we want to check if we are connected and we ping the router.

# ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=3.95 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.492 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.486 ms
^C
--- 192.168.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms

rtt min/avg/max/mdev = 0.486/1.645/3.957/1.634 ms

Ctrl+C for stopping.

OK, lets see what happens to our interface and rooting table:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
   link/ether 00:1d:60:0f:eb:c6 brd ff:ff:ff:ff:ff:ff
   inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0
   inet6 fe80::21d:60ff:fe0f:ebc6/64 scope link
   valid_lft forever preferred_lft forever

Now we have an ip addres at 129.168.1.100 , this because it is the first free ip on the router. Lets see our rooting table:

# ip route show
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.100  metric 202
default via 192.168.1.1 dev eth0  metric 202

Ok, this is nice now lets deal with wireless.

Configuring wlan0 with Automatic IP (DHCP)

Read eth0 with DHCP for more detailed information

Now, it’s the same story, if you expect finding here WPA2, WEP, WPA2-Enterprise how to, it’s not the section, here we are going to use an OPN (Open) Access Point with essid “linksys”. Now the wlan0 interface is up, if not #ip link set wlan0 up Than we connect our wireless card with the Access Point

#iwconfig wlan0 essid "linksys"
  • Case 1

We have automatic dhcp client running and this is all and we are connected

  • Case 2

We don’t have dhcp client running so we need to run it on the interface: In this case:

dhcpcd wlan0
dhcpcd: version 5.2.2 starting
dhcpcd: wlan0: rebinding lease of 192.168.1.100
dhcpcd: wlan0: NAK: from 192.168.1.1
dhcpcd: wlan0: broadcasting for a lease
dhcpcd: wlan0: offered 192.168.1.102 from 192.168.1.1
dhcpcd: wlan0: acknowledged 192.168.1.102 from 192.168.1.1
dhcpcd: wlan0: checking for 192.168.1.102
dhcpcd: wlan0: leased 192.168.1.102 for 86400 seconds
dhcpcd: forking to background

We ping for being shore that we are connected:

ping -c 2 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=4.96 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.770 ms
--- 192.168.1.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.770/2.869/4.969/2.100 ms

Configuring eth0 with Static IP

Indeed here we must Stop the DHCP server on our Router, so we point our browser to http://192.168.1.1 , log – in and see around about dhcp settings, than stop the dhcp server. Now, we suppose that your computer have never been connected with that router so, I’m going to clear my connection info with:

ip link set wlan0 down

Setting the interface down, automatically clears out connection info. Now, in the Dynamic DHCP we get the IP and Default Gateway from the DHCP server running on the router, but now that it is not running any more on the server how we’r going to get this data?

  • We are going to supply this data to our interface eth0

Now, we can get any ip that we like, and we now that the router is on 192.168.1.1 But if we don’t know this info? -Check your router quick start guide, or google it. Ok, now we connect the ethernet cable with our ethernet port on laptop and the ethernet port on the router. Ok, here we go, if we run dhcpcd eth0 nothing happens because there is not anymore the dhcp server running to give us the date so now:

For connecting in the correct way with the router we need 3 important data: Ip address Subnet Mask Default Gateway Broadcast Address The only 2 wee need to specify for make this connection work are IP address , and the Default Gateway. The range of the Ip address must be of course 192.168.0.* The ip address lets say we want 192.168.0.200 How to find the subnet mask? (yes I know is 255.255.255.0 but lets suppose that you don’t) We use a tool called ipcalc which is not currently installed on my machine so: $ipcalc 192.168.1.200 And from the output we get netmask 255.255.255.0 Broadcast is : 192.168.1.255 We use ipcalc, very nice tool helping with info about 1 ip. But normally the ip are :

   /8
   /16
   /24

Or, their dotted-quad equivalents:

   255.0.0.0
   255.255.0.0
   255.255.255.0

Adding IP, subnet and broadcast address Sow, we find that our selected ip 192.168.1.200 have a netmask 255.255.255.0 and we all ready know our router ip 192.168.1.1 The broadcast from ipcalc was 192.168.0.255. PS:Anyway we need to now only the router gateway ip (because the IP is of our selection) and we must select an ip in the right range. In this case 192.168.1.* from 2-254

ip addr add 192.168.1.200/24 eth0
or the other way
ifconfig eth0 192.168.1.200 netmask 255.255.255.0

If you are not shore about your subnet mask you just add your ip and than the ip program will calculate automatically your Subnet Mask
Here our nice output:

#ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
   link/ether 00:1d:60:0f:eb:c6 brd ff:ff:ff:ff:ff:ff
   inet 192.168.1.200/24 brd 192.168.0.255 scope global eth0
   inet6 fe80::21d:60ff:fe0f:ebc6/64 scope link
      valid_lft forever preferred_lft forever

After this we add the route

ip route add 192.168.1.1 dev eth0
(this will work btw but if we want to add a default gateway than we just)
ip route add default 192.168.1.1 dev eth0

Now:

#ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
   link/ether 00:1d:60:0f:eb:c6 brd ff:ff:ff:ff:ff:ff
   inet 192.168.1.200/24 scope global eth0
   inet6 fe80::21d:60ff:fe0f:ebc6/64 scope link
      valid_lft forever preferred_lft forever

and

# ping -c 3 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.490 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.443 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.492 ms
--- 192.168.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.443/0.475/0.492/0.022 ms

Now we see that we are connected. Lets deal with the wireless connection.

Configuring wlan0 with Static IP

  • Set all interfaces down and than again up.

Than:

ip link set wlan0 up
ip addr add 192.168.1.200/24 dev wlan0
ip route add 192.168.1.1 dev wlan0

 #ip addr show wlan0
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
   link/ether 00:18:de:c7:a0:6b brd ff:ff:ff:ff:ff:ff
   inet 192.168.1.200/24 scope global wlan0
   inet6 fe80::218:deff:fec7:a06b/64 scope link
      valid_lft forever preferred_lft forever
# ping -c 3 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.826 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.715 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.752 ms
--- 192.168.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.715/0.764/0.826/0.051 ms

Troubleshooting

  • Checking for duplicate ip address on your network:
arping  -c5 -D 192.168.1.1 -I wlan0
ARPING 192.168.1.1 from 0.0.0.0 wlan0
Unicast reply from 192.168.1.1 [00:1D:7E:B2:B7:90] for 192.168.1.1 [00:1D:7E:B2:B7:90] 1.752ms
Sent 1 probes (1 broadcast(s))
Received 1 response(s)