Linux basic network - Configure ip address
If you want to access Internet or your local network, you must have a network card (NIC). The drivers needed can be found in slackware/n3/netmods.tgz in your Slackware CD. If you installed all packages, then you must have the netmods package in your system already.
Linux network configuration
There are many network utilities in Linux that can be used to configure Ethernet ip address, netmask, routing table, name server and so on. Below are essential Linux commands used to configure Linux ip address.
Linux ifconfig command
The Linux ifconfig command can be used to configure a network interface card or Ethernet card. If the Linux ifconfig command issued without any argument or option, it displays the status of the currently active interfaces. See part of ifconfig manual page below:
NAME
ifconfig - configure a network interface
SYNOPSIS
ifconfig [-v] [-a] [-s] [interface]
ifconfig [-v] interface [aftype] options | address ...
DESCRIPTION
Ifconfig is used to configure the kernel-resident network interfaces.
It is used at boot time to set up interfaces as necessary. After that,
it is usually only needed when debugging or when system tuning is
needed.
If no arguments are given, ifconfig displays the status of the currently
active interfaces. If a single interface argument is given, it
displays the status of the given interface only; if a single -a argument
is given, it displays the status of all interfaces, even those
that are down. Otherwise, it configures an interface.
|
Here is a complete usage syntax:
Usage:
ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
[add <address>[/<prefixlen>]]
[del <address>[/<prefixlen>]]
[[-]broadcast [<address>]] [[-]pointopoint [<address>]]
[netmask <address>] [dstaddr <address>] [tunnel <address>]
[outfill <NN>] [keepalive <NN>]
[hw <HW> <address>] [metric <NN>] [mtu <NN>]
[[-]trailers] [[-]arp] [[-]allmulti]
[multicast] [[-]promisc]
[mem_start <NN>] [io_addr <NN>] [irq <NN>] [media <type>]
[txqueuelen <NN>]
[[-]dynamic]
[up|down] ...
<HW>=Hardware Type.
List of possible hardware types:
loop (Local Loopback) slip (Serial Line IP) cslip (VJ Serial Line IP)
slip6 (6-bit Serial Line IP) cslip6 (VJ 6-bit Serial Line IP) adaptive (Adaptive Serial Line IP)
strip (Metricom Starmode IP) ash (Ash) ether (Ethernet)
tr (16/4 Mbps Token Ring) tr (16/4 Mbps Token Ring (New)) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) rose (AMPR ROSE) tunnel (IPIP Tunnel)
ppp (Point-to-Point Protocol) hdlc ((Cisco)-HDLC) lapb (LAPB)
arcnet (ARCnet) dlci (Frame Relay DLCI) frad (Frame Relay Access Device)
sit (IPv6-in-IPv4) fddi (Fiber Distributed Data Interface) hippi (HIPPI)
irda (IrLAP) ec (Econet) x25 (generic X.25)
eui64 (Generic EUI-64)
<AF>=Address family. Default: inet
List of possible address families:
unix (UNIX Domain) inet (DARPA Internet) inet6 (IPv6)
ax25 (AMPR AX.25) netrom (AMPR NET/ROM) rose (AMPR ROSE)
ipx (Novell IPX) ddp (Appletalk DDP) ec (Econet)
ash (Ash) x25 (CCITT X.25)
|
See ifconfig command invoke with no option example below:
root@slackware:~# ifconfig eth0 Link encap:Ethernet HWaddr 00:aa:11:bb:22:cc inet addr:10.10.0.6 Bcast:10.21.35.255 Mask:255.255.0.0 UP BROADCAST RUNNING 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:11 Base address:0x1080 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 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:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) |
The first paragraph above shows the first Ethernet card, eth0 configuration. The line in red shows Ethernet ip address, broadcast and netmask. The second paragraph shows localhost or loopback configuration.
This is an example on how to use ifconfig command to setup a new Linux ip address for the first Ethernet card:
root@slackware:~# ifconfig eth0 192.168.1.5 netmask 255.255.255.0 up
|
Linux route command
After setting up a Linux ip address with ifconfig command, use Linux route command to set up static routes to specific hosts or networks. Linux route command is a tool where you can setup where to send which data. Basically you can use route command to show and manipulate routing table. This is an example of how to use route command in Linux. Issue route command without any option will print current routing table.
To add a new ip route via eth0 (first Ethernet card), issue route add command in this format:
route add -net <ip> netmask <ip> dev eth0
root@slackware:~# route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0
|
You can also add a gateway of the network:
route add -net <ip> gw <ip> netmask <ip> dev eth0
root@slackware:~# route add -net 192.168.1.0 gw 192.168.1.1 netmask 255.255.255.0 dev eth0
|
Now, check the routing table again:
root@slackware:~# 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 eth0
loopback * 255.0.0.0 U 0 0 0 lo
default 192.168.1.1 0.0.0.0 UG 1 0 0 eth0
root@slackware:~#
|
We can see all configurations we made is in the result above.
Slackware netconfig
In Slackware, a setup program called ‘netconfig’ is very easy to use and very helpful for a beginner to setup Linux ip address including basic network configuration. Let’s try it. You must login as root because as a normal user, you don’t have power to configure network. From root command prompt, type ‘netconfig’ and Enter. You'll have a screen like this:
Enter your hostname for example ‘linuxserver’. Move to <ok> by using the Tab key, Enter to continue.
Now you must provide a domain name for your host. Enter your domain name. When you finished, press Enter to continue.
We’ll learn how to set up static IP address now. Use arrow key to move up and down. Choose ‘Static IP’ and Enter. On the next screen, you have to provide an IP address. Enter your IP address and Enter to continue.
Now Enter the netmask.
Enter your gateway IP address. If you don’t have any gateway yet, or you are planning to use this server as a gateway, then use the same IP address.
You’ll be asked whether you will be accessing a name server. The name server here means your DNS server address or your ISP DNS ip address.
Enter your name server ip address. If you are using name server, you can enter it here
In this screen, you have to confirm your network setup. Move up and down using arrow key. If you want to edit something, you can do it now, and Tab to edit and Enter.
When you are done, Tab to ‘Accept’ and Enter. If you accept the setting, Enter one more time to confirm. That’s it, you are done. You will have the root command prompt again.
Type ‘clear’ at the root command prompt to clear the screen.
Normally, the ifconfig command is used to configure network interface card. Slackware make our job easier with netconfig. However, ifconfig is still an important Linux command. The ifconfig command can be used to check our Linux network configuration.
Let's confirm what we’ve done above with ifconfig command. Type 'ifconfig' and enter as example below:
root@slackware:~# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 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:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
root@slackware:~#
|
Check the inet addr and Mask. What? We still have the old data? Don't worry, keep on reading.
Stop and start linux service
So now we must update the Linux network configuration data that we setup with netconfig just now. What we have to do is restart the service which means stop and start the service again. Remember about /etc/rc.d directory? The service we want to restart is rc.inet1. This is the complete command to stop and start a service:
root@slackware:~# /etc/rc.d/rc.inet1 stop root@slackware:~# /etc/rc.d/rc.inet1 start root@slackware:~# ifconfig eth0 Link encap:Ethernet HWaddr 00:aa:11:bb:22:cc inet addr:192.168.1.5 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING 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:11 Base address:0x1080 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 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:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) root@slackware:~# |
You can also use '/etc/rc.d/rc.inet1 restart' command to do the above task.
Setup and configure a second network card
If we have another network card in the computer, then we can configure it now. However we can't use netconfig anymore. The netconfig tool is used to configure Linux ip address for the first network card. For the second network card, we can setup ip address by manually edit the /etc/rc.d/rc.inet1.conf file. Open the file with text editor, such as vim and in the eth1 section (a second network card), add your network configuration data. Also, you should add HWADDR data, which is the mac address of the network card because we don't want the eth0 and eth1 swap every time we reboot Linux. The 'HWADDR' data is unique. To see check what your mac address is, use ifconfig command as in the ifconfig example above. Write the address and then open /etc/rc.d/rc.inet1.conf file with text editor. See example below:
# /etc/rc.d/rc.inet1.conf
#
# This file contains the configuration settings for network interfaces.
# If USE_DHCP[interface] is set to "yes", this overrides any other settings.
# If you don't have an interface, leave the settings null ("").
# You can configure network interfaces other than eth0,eth1... by setting
# IFNAME[interface] to the interface's name. If IFNAME[interface] is unset
# or empty, it is assumed you're configuring eth
|
That's it, save the file and restart rc.inet1 daemon. Run the 'ifconfig' command to update the new network card data.
root@slackware:~# ifconfig
eth0 Link encap:Ethernet HWaddr 00:aa:11:bb:22:cc
inet addr:192.168.1.5 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::223:cdff:feb4:9f1f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1895974 errors:0 dropped:28 overruns:0 frame:0
TX packets:411289 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:674815483 (643.5 MiB) TX bytes:73677358 (70.2 MiB)
Interrupt:17 Base address:0xe800
eth1 Link encap:Ethernet HWaddr 33:aa:44:bb:55:cc
inet addr:192.168.2.1 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::21b:fcff:fed3:e47f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:332574 errors:0 dropped:35 overruns:0 frame:0
TX packets:470231 errors:0 dropped:0 overruns:0 carrier:8
collisions:0 txqueuelen:1000
RX bytes:64241167 (61.2 MiB) TX bytes:498941589 (475.8 MiB)
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:18 errors:0 dropped:0 overruns:0 frame:0
TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:980 (980.0 B) TX bytes:980 (980.0 B)
root@slackware:~#
|
Linux ping command
The ping command is famous not only in Linux system but windows as well. Normally, it is used to check network connection between two hosts. However, ping offers many options in Linux. The ping manual is a good tutorial, make sure you read it.
Ok now let's check our network interface with ping. We can try pinging our gateway router if we already in the network but if in standalone pc, ping our own NIC just for practice and look how things work.
The ping format is ping <option> <target ip>:
root@slackware:~# ping -c3 192.168.1.5 PING 192.168.1.5 (192.168.1.5) 56(84) bytes of data. 64 bytes from 192.168.1.5: icmp_seq=1 ttl=64 time=0.200 ms 64 bytes from 192.168.1.5: icmp_seq=2 ttl=64 time=0.287 ms 64 bytes from 192.168.1.5: icmp_seq=3 ttl=64 time=0.290 ms --- 192.168.1.5 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 1998ms rtt min/avg/max/mdev = 0.200/0.259/0.290/0.041 ms root@slackware:~# |
In the example above, we use ping command with -c3 which means we ping to count and print output three times only.

Thank you! My professor
Thank you! My professor could not have made this seem more difficult. You have clarified the subject for me.
this link i found from
this link i found from google search.
it is very good tutorial where i fill my requirement.