Pages

Basic Network Configuration in Linux

Many Linux distributions now have tools to configure the basic settings for the network connection through graphical interfaces, however, sometimes it is easier to do this task by commands. I leave the series of commands that need to change ip in Linux using the shell (or console or command line).

The ifconfig command to define network settings for different devices, for example in the case of the eth0 and eth1 interfaces are the following commands, as you can see there are several ways to configure the same.

For example:

ifconfig eth0 192.168.1.10 netmask 255.255.255.0 or ifconfig eth0 192.168.1.10/24

if you have a second network card, the command would be:

ifconfig eth1 192.168.2.10 netmask 255.255.255.0 or ifconfig eth1 192.168.2.10/24

This allows us to establish a connection to any computer that is within the networks directly connected to the computer. To access a network different from ours, we need to configure a default route (assuming that the IP address 192.168.1.1 belongs to a device that is responsible for keeping our traffic to other networks)

route add default gw 192.168.1.1

Finally, we need to configure at least one primary DNS server that is responsible for making translations of URLs to IP addresses. For this you can edit the /etc/resolv.conf file or use something like the echo command:

echo nameserver 192.168.1.200 > /etc/resolv.conf

Finally, you must restart the network service and ready. To mention, the command can be: service network restart or /etc/init.d/network restart (on some distributions is /etc/init.d/networking restart)

0 Comments:

Post a Comment