This tutorials shows how to set up network and configure network parameters from command line interface on Linux systems. Since one should not have hard time configuring it from graphical user interface (few mouse clicks once You find the right tool) this tutorial will orient on configuration from cli. Also notice that various linux systems have slightly different configuration methods.
To determine Your Network interface card (NIC), You can use ifconfig command. Most of todays systems will mark Your NICs as devices eth0, eth1 and so on... depending on how many phisical interfaces (NICs) You have installed in your server.
We can use ifconfig to list installed NIC-s:
Ifconfig command is also used to bring NIC up or down and to assign network parameters like ip
address and subnetmask:
Route command is usually used to configure static routing and to populate routing-tables, but we can also use it to setup default gateway. Computers and devices can directly communicate with each other if they are located in the same subnet. However, if computer from one subnet tries to send a packet to device in another subnet, computer first has to send data to it's default gateway which than forwards the packets to it's destination.
To setup a default gateway address to 192.168.1.1 for the interface eth0 on a Linux machine, we can use this command:
However, configuring the network with ifconfig and route commands is not permanent. Address assigned this way will not be saved if system reboots, or tcp/ip stack restarts. To assign static ip address to a interface permanently, You have to edit file /etc/network/interfaces:
After successfuly editing and saving /etc/network/interfaces, You have to restart tcp/ip stack so changes can take effect.
Network can be restarted with:
Another look on ifconfig shows that network is now configured properly:
To setup the addresses of a DNS servers, edit the file /etc/resolv.conf.
For example to setup the DNS server address of a Google's DNS server, add the line nameserver after which folows the ip address of the DNS server:
If want to setup DHCP on NIC, content of /etc/network/interfaces has to be replaced with these lines:
After configuring network parameters, TCP/IP stack has to be restarted:
Linux (Debian) network configuration (from CLI):
Red Hat / Fedora network configurationConfiguration of network on Red Hat based systems (example Fedora) is done by editing few configuration files stored in /etc/sysconfig/network-scripts/ directory. Based on the interface we want to configure, we can edit or create (if the files don't exists) interface files.
For first network card, we can create /etc/sysconfig/network-scripts/ifcfg-eth0, for second NIC we would create /etc/sysconfig/network-scripts/ifcfg-eth1 and so on...
In /etc/sysconfig/network we can setup default gateway (router IP) and hostname:
After successful saving the files, we have to restart networking:
Comments
Post a Comment