Сетевое взаимодействие

Revision as of 19:12, 30 December 2022 by FuzzyBot (talk | contribs) (Updating to match new version of source page)
Other languages:
English • ‎русский

Обзор

Сеть в Manjaro, как правило, работает из коробки без какого-либо специального вмешательства пользователя. В этой статье представлены некоторые специфические обстоятельства, с которыми могут столкнуться некоторые пользователи и даны советы по их преодолению.


Ручная настройка DNS-серверов

Обычно DNS-серверы предоставляются провайдером автоматически через DHCP. Однако иногда необходимо использовать DNS-серверы, отличные от предоставленных провайдером. В такой ситуации Вы можете обнаружить, что адреса ваших DNS или других нестандартных серверов имен сбрасываются при перезагрузке, поскольку /etc/resolv.conf может быть перезаписан NetworkManager или в процессе загрузки. Здесь мы рассмотрим некоторые методы сохранения ваших настроек.


NetworkManager

Если вы используете NetworkManager - это одно из решений проблемы. Каталог conf.d NetworkManager находится в /etc/NetworkManager/conf.d. Там Вы можете разместить фрагменты, управляющие работой NetworkManager. Файлы должны иметь имя с номером и описанием его назначения и всегда заканчиваться .conf. Файлы применяются в числовом порядке от низшего к высшему. Конфигурация в файле с большим номером отменяет то, что могло быть настроено в файле с меньшим номером.

Использование resolvconf

Чтобы скрипт resolvconf обрабатывал файл resolv.conf для NetworkManager. Создайте файл конфигурации в каталоге NetworkManager conf.d

/etc/NetworkManager/conf.d/20-rc-manager.conf

Сохраните файл с таким содержимым

[main]
rc-manager=resolvconf

Чтобы эффективно сделать обработку DNS ручной задачей, создайте файл с именем

/etc/NetworkManager/conf.d/99-dont-touch-my-dns.conf

Сохраните файл с таким содержимым

[main]
dns=none


/etc/resolvconf.conf

The resolvconf.conf file is a shell script that is sourced by resolvconf, meaning that resolvconf.conf must contain valid shell commands. Take a look at its man page for more details and commands. The file is located at /etc/resolvconf.conf and will require root privelege to edit. For more information on how to edit a configuration file owned by root, please review this article.


As an example, we will prepend OpenDNS nameservers to the top of our resolvconf file whenever called. We can achieve this by adding the following lines to the bottom of resolvconf.conf.

# OpenDNS servers
name_servers="208.67.222.222 208.67.220.220"


After making any changes simply update and apply your settings with the following command

user $ sudo resolvconf -u COPY TO CLIPBOARD

dhcpcd и resolv.conf.head/tail

Note
Most Manjaro installs will not be using dhcpd by default


An alternative solution if you are using dhcpd is to input our settings to the /etc/resolv.conf.head file. If this file does not exist then create it. The contents of /etc/resolv.conf.head get sent to the top of /etc/resolv.conf during the boot process.


Following our previous example, if we want to use the OpenDNS servers with this method, we could place the following in the file:

# OpenDNS servers
nameserver 208.67.222.222
nameserver 208.67.220.220


Настройка статического IP-адреса

Использование графической утилиты

Most editions of Manjaro come with some type a GUI tool or applet to manage NetworkManager. This is the easiest way to set a static IP. Simply go into the tool, usually in the system tray or menu, and input the required parameters for your network.


Использование systemd

If you don't want to use NetworkManager the next easiest thing is to configure a static IP in systemd.


First, make sure you aren't running NetworkManager

user $ sudo systemctl disable --now NetworkManager.service COPY TO CLIPBOARD


Next you will need to find the name of your network device. To locate the name, use the command ip a as seen here:

ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:02:55:c4 brd ff:ff:ff:ff:ff:ff
    inet 172.16.197.200/24 brd 172.16.197.255 scope global dynamic noprefixroute ens33
       valid_lft 1725sec preferred_lft 1725sec
    inet6 fe80::7116:2769:dac:6314/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever


lo is the loopback device which can be ignored for the purposes of this article. The device we need here is identified above as ens33. We will need this name in the next step.


Now create or edit a file to hold the network configuration at /etc/systemd/network/devicename.network. Using the example above, the file would be called /etc/systemd/network/ens33.network. This file will need to be created/edited as root. For more information on how to do that please review this article. An example of the contents of the file would look like this:

[Match]
Name=enp0s3
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
[Network]
Address=192.168.1.101/24
Gateway=192.168.1.1
DNS=208.67.222.222
DNS=208.67.220.220


All that remains is to start and enable the service using:

user $ sudo systemctl enable --now systemd-networkd.service COPY TO CLIPBOARD

Использование dhcpcd вместо NetworkManager

NetworkManager is the default solution for networking on most Manjaro editions. If you would prefer to use dhcpcd, that is also supported.


First, ensure NetworkManager is disabled and not running

user $ sudo systemctl disable --now NetworkManager.service COPY TO CLIPBOARD


Next, start and enable the dhcpcd service

user $ sudo systemctl start --now dhcpcd.service COPY TO CLIPBOARD

Смотрите также