User Tools

Site Tools


настройка_сети_в_linux

Настройка сети в Linux

Команды для настройки

Настройка ip параметров с использованием утилиты ip

# apt install iproute2

$ ip link show

# ip link set enp0s3 up

# ip addr add 172.16.1.X/24 dev enp0s3

# ip addr show dev enp0s3

# ip route add default via 172.16.1.254

# ip addr del 172.16.1.X/24 dev enp0s3

# ip addr flush dev enp0s3

Динамическая настройка ip параметров

# dhclient enp0s3

# ip a

Настройка ip параметров с использованием классических утилит

ubuntu# apt install net-tools

# ifconfig -a

# ifconfig eth0 inet 172.16.1.X/24

# route add default gw 172.16.1.254

Настройка hostname

# hostname server.corpX.un

Команды для диагностики

# ip link show

# ip a

# ifconfig -a

# ethtool eth0
# ethtool -s eth1 speed 100 duplex full
# ethtool -s eth1 autoneg on

# arp -n
# ip n s
# ip n f all

# netstat -rn
# ip r

# ping 8.8.8.8

# tracepath -n ya.ru

# netstat -tupan
# lsof -i -P

# ss -anptu

Файлы конфигурации

Настройка имен интерфейсов

Общие файлы конфигурации

# cat /etc/hosts
127.0.0.1       localhost

172.16.1.X      server.corpX.un server
# apt remove resolvconf

# cat /etc/resolv.conf
nameserver 172.16.1.254
search corpX.un

Файлы конфигурации ifupdown (Debian/Ubuntu<18)

Статическая настройка параметров

# cat /etc/hostname
server.corpX.un
# cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto enp0s3
iface enp0s3 inet static
        address 172.16.1.X
        netmask 255.255.255.0
        gateway 172.16.1.254

# apt install resolvconf
#        dns-nameservers 172.16.1.254
#        dns-search corpX.un


### Alias example ###
# auto eth0:0
# iface eth0:0 inet static
#         address 192.168.1.10
#         netmask 255.255.255.0

### Bridge example ###
### http://bwachter.lart.info/linux/bridges.html ###
###
### https://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg1812219.html
### В Debian 11 требуется Promoskye режим в виртуализации
###
# apt install bridge-utils

# auto br0
# iface br0 inet static
#         address 172.16.1.X
#         netmask 255.255.255.0
#         gateway 172.16.1.254
#         bridge_ports eth0 eth1
#         bridge_stp off
#         bridge_maxwait 5
#         post-up /sbin/brctl setfd br0 0

### 802.1q example ###
# apt install vlan

# auto vlan2
# iface vlan2 inet static
#         address 192.168.100+X.1
#         netmask 255.255.255.0
#         mtu 1500
#         vlan_raw_device eth0

### UP iface without ip example ###
# auto eth1
# iface eth1 inet manual
#         up ip link set eth1 up
# ifup enp0s3

# ifdown --force enp0s3

Динамическая настройка параметров

client1# cat /etc/hostname
client1
client1# :> /etc/resolv.conf
client1# cat /etc/hosts
127.0.0.1     localhost

127.0.1.1 client1
  • Без GUI
# cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
# apt install network-manager

Файлы конфигурации Ubuntu >= 18

Отключение cloud-init

# apt purge cloud-init

netplan

# cat /etc/netplan/01-netcfg.yaml
network:
  version: 2
  ethernets:
    enp0s3:
      addresses: [172.16.1.200+X/24]
      gateway4: 172.16.1.254
#      nameservers:
#        addresses: [172.16.1.254]
# netplan try

# netplan apply

systemd-resolved

# cat /etc/resolv.conf
search corpX.un
nameserver 127.0.0.53
# cat /etc/systemd/resolved.conf
[Resolve]
DNS=172.16.1.254

Без Netpaln

# apt install ifupdown net-tools

# echo 'network: {config: disabled}' > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

ubuntu18# rm /etc/netplan/50-cloud-init.yaml

ubuntu20# rm /etc/netplan/00-installer-config.yaml

Без systemd-resolved

# systemctl disable systemd-resolved.service
# systemctl stop systemd-resolved

# rm /etc/resolv.conf    # this is link

Файлы конфигурации CentOS/SL/RHEL

# cat /etc/hostname
server.corpX.un
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# HWADDR=00:0C:29:C0:F8:54
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.16.1.100+X
NETMASK=255.255.255.0
DNS1=172.16.1.254
DOMAIN=corpX.un
GATEWAY=172.16.1.254
# cat /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
BOOTPROTO=static
ONBOOT=yes
# HWADDR=00:0C:29:C0:F8:54
IPADDR=10.N.M.100+X
NETMASK=255.255.255.0

Для Centos 6

# cat /etc/sysconfig/network
# NETWORKING=yes
# NETWORKING_IPV6=no
# HOSTNAME=centos.corpX.un
# GATEWAY=172.16.1.254

Применение файлов настроек

# hostname centos.corpX.un

# ifup enp0s3

Файлы конфигурации Gentoo

# cat /etc/conf.d/hostname
hostname="server.corpX.un"
# cd /etc/init.d
# ln -s net.lo net.enp0s3
# cat /etc/conf.d/net
config_enp0s3="172.16.1.X/24"
routes_enp0s3="default via 172.16.1.254"
# rc-update add net.enp0s3 default

Управление разрешением имен (getaddrinfo)

root@nessus.isp.un:~# host ru.archive.ubuntu.com
ru.archive.ubuntu.com is an alias for mirror.yandex.ru.
mirror.yandex.ru has address 213.180.204.183
mirror.yandex.ru has IPv6 address 2a02:6b8:0:201::1
root@nessus.isp.un:~# cat /etc/gai.conf
...
precedence 2a02:6b8::/32   0
...

Настройка bonding

bond ifupdown

# apt install ifenslave

# cat /etc/network/interfaces
...
iface eth0 inet manual

iface eth1 inet manual

auto bond0
iface bond0 inet static
        address 192.168.X.10
        netmask 255.255.255.0
        gateway 192.168.X.1
        slaves eth0 eth1
        bond-mode active-backup
        bond-miimon 100
        bond-primary eth0

bond netplan

# cat /etc/netplan/01-netcfg.yaml
network:
  version: 2
  bonds:
    bond0:
      addresses: [192.168.X.10/24]
      gateway4: 192.168.X.1
      interfaces: [eth0, eth1]
      parameters:
        mode: active-backup
        mii-monitor-interval: 100
        primary: eth0
  ethernets:
    eth0: {}
    eth1: {}

Отладка

# cat /proc/net/bonding/bond0
настройка_сети_в_linux.txt · Last modified: 2022/05/26 11:35 by val