How to set up a local network in Ubuntu

In the process of working with a computer there are a variety of tasks, one of which is to configure the local network. This article will take a detailed look at how to configure the local network in the Ubuntu operating system. So let's get started.

Setting up a local network in Ubuntu is done using commands.

The console network configuration in all Linux-like operating systems, including Ubuntu, is performed using the special ifconfig command. If you simply register this command in the terminal, the console will show all the network interfaces that are running on the PC at that moment. It looks like this:

eth0 Link encap: Ethernet HWaddr 00: 04: 75: c1: e2: ab

inet addr: Bcast: Mask:



eth1 Link encap: Ethernet HWaddr 00: 04: 75: c1: e2: 6b

inet addr: Bcast: Mask:



lo Link encap: Local Loopback

inet addr: Mask:



The first column contains the names of the interfaces, and the second - the settings of these same interfaces. The command ifconfig eth0 only displays the settings of interface eth0. To disable or enable the eth0 interface, enter the following commands:

sudo ifconfig eth0 down

sudo ifconfig eth0 up

Please note that interface management requires so-called superuser rights.

To change the interface settings, list the following commands:

sudo ifconfig eth1 inet

change the IP address of the eth1 interface to

sudo ifconfig eth0 hw ether 00: 12: 34: 56: 78: 90

will change the MAC address to 00: 12: 34: 56: 78: 90

sudo ifconfig eth0 netmask

change the eth0 subnet mask of interface eth0 to

However, parameters set in this way are reset after the computer is restarted. To avoid this, change the settings in the network interface configuration file, which is located in / etc / network / interfaces. This file looks like this:

# This file is the network interfaces available on your system

# and how to activate them. For more information, see interfaces (5).

# The loopback network interface

auto lo

iface lo inet loopback

# The primary network interface

auto eth0

iface eth0 inet static


#hwaddress ether 12: 34: 56: 78: 90: 12






# The secondary network interface

auto eth1

iface eth1 inet static



To set the address of the DNS server, go to the / etc / network / interfaces file, but notice that usually the addresses of the DNS servers in Ubuntu are managed through the /etc/resolv.conf file, the syntax of this configuration file is extremely simple, and looks like this



After making changes to these configuration files, restart the network service with the command:

sudo /etc/init.d/networking restart

If you need your computer to receive network settings dynamically (via DHCP), write the following lines in the / etc / network / interfaces file:

auto eth0

iface eth0 inet auto

To dynamically update network settings, list:


To stop or start the network service, use the commands:

sudo /etc/init.d/networking stop

sudo /etc/init.d/networking start

If you look at the configuration file in question, in the settings of the interface eth0, the line that changes the MAC address is commented out. This is done because if it is not commented out, the network service may not start, and you may need to register to change the MAC address:

sudo ifconfig eth0 down

sudo ifconfig eth0 hw ether 12: 34: 56: 78: 90: 12

sudo ifconfig eth0 up

sudo /etc/init.d/networking restart

Alternatively, you can write a bash script.

In the / home / user folder, create a file called mynetconfig and copy the code into it:

echo "######## OTKLYCHENIE eth0 #######"

sudo ifconfig eth0 down

echo "##### MENYAEM MAC ADRES #####"

sudo ifconfig eth0 hw ether 00: 13: 8f: cb: 10: 21

echo "######## VKLUCHAEM eth0 #########"

sudo ifconfig eth0 up


sudo /etc/init.d/networking restart

echo "KONEC"

Now, instead of these lines, you will have to write only one command: / home / user / mynetconfig

Next, copy the mynetconfig file to the / use / local / bin directory. Now you can run the script simply using the command mynetconfig. To start the script immediately when the system boots, copy it to /etc/init.d/, then open the console and go to /etc/init.d/, then run the command:

update-rc.d mynetconfig defaults 99,

where mynetconfig is the name of the script;

defaults - perform on all modes from second to fifth downloads;

99 - boot order.

To remove a script from startup, open the /etc/init.d/ directory and type:

update-rc.d -f mynetconfig remove

There is another way to add a script to autoload. Simply enter the name of the script in the /etc/rc.local file or delete it if you want to remove the script. The first method is somewhat more complicated, but it is worth giving preference to it, since in this case it will be possible to choose the order and mode of loading, which may be important in some situations.

Now consider how to connect a network drive in Ubuntu. This is done quite simply. First open the "Go to" menu and select "Connect to Server". In the window that opens, you will need to specify the type of service and other general data. Click the Connect button. Next, you will need to enter your password and click on the "Connect" button. Is done. Everything is pretty easy and fast.

Now you will know how to set up a network through the console in Ubuntu, as well as how to connect a network drive. Write in the comments if you managed to cope with this task, share your experience with other users, and ask any questions that interest you on the topic of this article.