If you want your computer on the network then you need to know a little about network and IP Addresses or Internet Protocol Addresses. In short, where the computer lives on the network.
For years this has been just IP or what people now call IPv4 and this is still the most common way of connecting to networks. IPv6 is in use now and at some stage in the not to distant future we sill see this taking over from IPv4. For the moment we will start with IPv4 addresses.
An IPv4 address would look similar to this: 192.168.1.100 , the address is written in what we call a dotted decimal format that represents 32 bit address space. An address made up from 32 ones or zeros, computer bits. Along with the address there is something called the subnet mask, this identifies which part of the address represents the networks and what part the host. In the simplest forms having a subnet mask of 255.255.255.0 applied to the previous IP address would give us a network of 192.168.1.0 and a host 100 on that network. If a host is on the same network as the originating device communication can happen directly; if it is seen as being on a different network then, usually this would mean that communication would be mediated by the default gateway or router on the network. An IP Address and subnet mask are required, the default gateway is optional. Without a default gateway though you may struggle to connect to hosts that are not on the same network.
- IP Address: 32 bit Address to locate the computer’s location or adress on the network
- Subnet Mask: 32 bit address denoting which parts of an address are the network and which parts of an address are the address of the host
- Default Gateway: Router to use where the network address is not known
To display the IP address configuration of a host we can use the tools ifconfig or ip. Traditionally Linux and UNIX administrators have become used to using ifconfig (/sbin/ifconfig) to both display and set an IP address. As this is in the sbin directory it may not be in the PATH variable for standard users and as such becomes and admin only tool even for just displaying information. To display information for the first ethernet card, etho use the command:
You see the output from the command in the following screenshot from one of my machines:
You can use ifconfig to both display and set address information. Permanent address configuration has to be made through configuration files not with commands like ip or ifconfig.
The new kid on the block is ip, (/sbin/ip), this can be used to display address configuration with:
ip address show eth0
This can be abbreviated to :
ip a s eth0
Again it can be used to configure the address as well as displaying it, like ifconfig these changes are not persistent if not made in the configuration files for the network interface. Although the command is in the /sbin directory there is also a symbolic or soft link in the /bin making it easily accessible to standard users who can use it to display information.
The real winner with the ip command is that it can be used to manage more than just the ip address, routes links, multicast addresses, ARP tables and more can be managed with ip.
- ip route show
- ip neighbor show
- ip maddr show
- ip link show
Much more of a swiss-army knife than ifconfig.
The IP address configuration can be STATIC or DYNAMIC , client computers are often configured with dynamic addresses from a DHCP or Dynamic Host Control Protocol , servers are often configured with static addresses. With a dynamic address you can, for example, connect your android phone to your WiFi network at home to gain internet access, connecting to the internet at your favourite coffee is just as easy, no changes to the configuration is required as the assignment is dynamic, the address, subnet mask and default gateway comes from the DHCP server on each network you connect to.
Like ifconfig the command route (/sbin/route), is the tradition command used in UNIX and Linux to display route information for a host. Both ip route show and the command route on its own will display the route table on the host. Usually the most important route is the default route, if no other route can be found to a network the default route is used.
The host will be configured with and IP Address but mainly users will find it easier to access hosts using DNS names (Domain Name Server), this way we can access our favourite websites with just a name, www.theurbanpenguin.com, rather than having to know its address. The system has to be configured with the Ip address of the DNS server or servers. This is most often in the file /etc/resolv.conf. The file uses the nameserver directive followed by the address of the server. The address of the servers can be delivered by DHCP for dynamically configured hosts.