Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Network configuration commands, binding, interface naming and detailed explanation of configuration files

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

One: three command families

When we manage the network in centos, we need to set the network properties for the network card. There are two types: automatic acquisition and manual configuration. Automatic acquisition requires at least one DHCP server in the network where the host is located, while manual configuration, that is, static specification, can use commands or modify configuration files. First of all, let's focus on the use of commands, including net-tools family (ifcfg family), iproute family, nm family: Network Manager. All three tools are subcommands of setup, which can be used in centos6.

The summary of the specific command is as follows:

Net-tools family (ifcfg family)

Ifconfig interface configuration command

View configuration information for network interfaces

Configure network properti

Manage interface statu

Route

View routing information

Configure routing information (gateways, static routes, static default routes)

Netstat

Review of status and statistics

Iproute family:

Ip OBJECT

Where OBJERT can be:

Management of addr:IP address and mask

Link: management of physical interfaces

Route: route management

Ss:

Viewing of status and statistics

Note: the above command can be applied to any linux distribution

Nm Family: Network Manager

Nmcli: command line tool

Tools for nmtui:text-window

The nm family can only be used in centos7

First of all, let's introduce in detail the three commands of the net-tools family (ifcfg family):

1.ifconfig command

Ifconfig-configure a network interface configure a network interface

1) ifconfig [interface]: used to view configuration information of network interfaces

If the ifconfig command is executed without any interface as a parameter, all active network interface information is displayed

If ifconfig naming is performed with a specific interface name as a parameter, information about the network interface is displayed regardless of whether the interface is active or not

Ifconfig interface address: the specified parameter used to configure the network interface

Ifconfig interface IP [/ PREFIX_LEN] [up | down]

Ifconfig interface IP netmask SUBNET_MASK [up | down]

Example:

# ifconfig eth2 172.16.100.105

# ifconfig eth2 172.16.100.105/24

# ifconfig eth2 172.16.100.105 netmask 255.255.255.192

# ifconfig eth2 up | down

Common options:

-a: displays all network interfaces, whether or not they are active

Example: ifconfig-a

2.route command: view and manage routing information:

The route entries in the routing table may include the following types

1. Host routing: the destination address is a specific single IP address

two。 Network routing: subnet routing, main network routing, supernetwork routing (aggregate routing CIDR)

3. Default route: a route entry with a destination address of 0.0.0.0plus 0, a route to any address

Common options:

-n: digitally display hostname (IP address) and port

Set routing information:

Route add [- net |-host] target [netmask Nm] [gw Gw] [[dev] If]

Route del [- net |-host] target [netmask Nm] [gw Gw] [[dev] If]

The method to set the default gateway: default is equal to-net 0.0.0.0Universe 0 netmask 0.0.0.0

Route add default gw 192.168.100.1

The method to delete the default gateway:

Route del default

Route del default gw 172.16.0.1

How to add a static route:

Route add-net 10.0.0.0 gw 8 gw 192.168.220.100 [dev eth3]

How to delete a static route:

Route del-net 10.0.0.0 Compact 8

Route del-net 10.0.0.0 gw 8 gw 192.168.220.100

3.netstat command:

Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships

Print network connections

[--tcp |-t]: only network connections related to TCP protocol are displayed

[--udp |-u]: only network connections related to UDP protocol are displayed

[--udplite |-U]: only network connections related to udplite protocol are displayed

[--sctp |-S]:

[--raw |-w]: displays network connections related to bare sockets

[--listening |-l]: displays TCP connections in LISTEN state

[--all |-a]: view any connection in all statu

[--numeric |-n]: host name, port number, user ID and other information in the digitized display result

[--numeric-hosts]

[--numeric-ports]

[--numeric-users]

[--extend |-e [--extend |-e]]: displays the result in an extended format

[--program |-p]: displays the ID of applications and processes related to the network connection

Common combinations of options:

-tan,-uan,-tnl,-unl,-tnlp,-unlp,-tunlp

Print routing tables

{--route |-r}: displays routing table information

[--numeric |-n]: digitized information

[--extend |-e]: displays extended information

Common combinations of options:

-rn.-rne.

Print interface statistics:

{--interfaces |-I |-I}

[--all |-a]

[--extend |-e]

[--verbose |-v]

[--program |-p]

[--numeric |-n]

Print Protocol statistics:

{--statistics |-s}: displays detailed statistical information of each protocol

[--tcp |-t]

[--udp |-u]

[--udplite |-U]

[--sctp |-S]

[--raw |-w]

And then the iproute family:

Ip:show / manipulate routing, devices, policy routing and tunnels

Ip [OPTIONS] OBJECT {COMMAND | help}

OBJECT: = {link | addr | route | netns}

Ip link COMMAND

COMMAND: add, delete, set, show, help

Ip link set-modify the configuration parameters of a network device

Ip link set [dev] IFACE_NAME {up | down}: activate or disable network interfaces

Ip link set [dev] IFACE_NAME [arp {on | off}]: whether to allow this network interface to use the ARP protocol

Ip link set [dev] IFACE_NAME name IFACE_NEW_NAME: to change the name of the network interface, you need to down the device first.

Ip link set [dev] IFACE_NAME [mtu MTU]: modify the MTU value of a network interface

Ip link set [dev] IFACE_NAME [netns PID]:

Ip link set [dev] IFACE_NAME [netns NAME]: adds the specified network interface to the specified network namespace

Ip link {show | list}: list shows all link interfaces; only link layer information is displayed

Ip link help: get short help information

Ip netns COMMAND-sets the network namespace in the kernel

Ip netns list: list shows all customized namespaces

Ip netns add NS_NAME: creating namespaces

Ip netns exec NS_NAME cmd: use the command in the specified namespace

Ip netns delete NS_NAME: deletes the specified namespace

Ip addr COMMAND-View and set layer 3 logical network addresses

Ip addr add IFADDR dev IFACE_NAME: adds an IP address to the specified network interface

Ip addr del IFADDR dev IFACE_NAME: removes the IP address from the specified network interface

Ip addr flush dev IFACE_NAME: clears all IP addresses configured on the specified interface

Ip addr {show | list} [dev IFACE_NAME]: displays the IP address configured on the network interface

Add multiple IP addresses to the network interface and be able to view it using ifconfig

Ip addr add IFADDR dev IFACE_NAME label IFACE_NAME_LABEL

Ifconfig IFACE_NAME_LABEL IFADDR

IFACE_NAME_LABEL: IFACE_NAME:#

Ip route COMMAND-View and set routing table information

Ip route {add | del} TARGET/PREFIX via NEXT_HOP [dev IFACE_NAME]

Ip route list

Two: naming of network interface

Each network interface in Linux has a name, and you can use the ifconfig command to query the interface in the current system. Are there any requirements or restrictions when naming these interfaces, such as format or length restrictions? On the surface, there seems to be no restriction that you can name it at will, and it can work well in general application scenarios, but there will be inexplicable problems because of the interface name in special applications. So you need a naming convention:

Cisco switch: fastethernet0/1,gigabitethernet0/1

Cisco Router: Ethernet0/0,fastethernet0/0

How the interface of linux is named:

a. The traditional way of naming:

Ethernet: an integer that ethx,x starts at 0, such as eth0,eth2.

PPP Network: PPPoE,PPP over Ethernet

PppX,X an integer starting at 0: for example: ppp0,ppp1,....

Loopback interface: lo,loopback

Used in centos6 and previous releases

b. Predictable naming scheme (centos7 start)

Many naming mechanisms can be supported:

1) name according to Firmware

The network card of each computer has a unique identifier in the hardware firmware of its computer, such as MAC address, manufacturer ID, electrical number, etc.

2) according to the physical topology:

Each computer has a fixed number of slots or interfaces on the motherboard, such as the first physical interface of the network card connected to the second slot on the motherboard.

Depending on the naming mechanism, we can have the following naming standards:

1) if Firmware or BIOS is the index information provided by the integrated device on the motherboard and the information is available, the device is named based on this index information, such as enoX,eno1,eno16777736,.

2) if Firmware or BIOS is the index information provided by the expansion slot on the motherboard and this information is available, the device is named according to this index information, such as ensX,ens0,ens2....

3) if the location information of the physical topology of the hardware interface exists and is available, the device can be named based on this information, such as enp1s0

4) if the definition displayed by the user, it can be named according to an address such as MAC, such as enx000c290045b3

5) if none of the above predictions are available, the traditional naming method will be used to name the network devices.

The format composition of the name:

En:Ethernet

Wl:wlan

Ww:wwan

Type of name:

0: the index number of the integrated device

S: the index number of the expansion slot

X: naming based on MAC address

Ps: index federated index number based on bus + expansion slot

III: configuration file of the network

Another way is to modify the configuration file when we need to configure the network. The configuration files related to IP, MASK, GATEWAY and DNS Server in CentOS6 are saved in / etc/sysconfig/network-scripts/ifcfg-IFACE_NAME, and their contents are explained as follows:

DEVICE: the name of this network interface

TYPE: the type of this network interface, the more common is Ethernet,Bridge,Token Ring,...

HWADDR: the physical address of this device, which is the MAC address in Ethernet

ONBOOT: whether to activate this device during system boot

NETBOOT: whether this device can be used for network boot

BOOTPROTO: what protocol is used to configure the properties of this interface when activating this interface

Dynamic configuration: dhcp,bootp

Static configuration: static,none

IPV6INIT: whether to initialize the IPV6 protocol on this interface

USERCTL: whether ordinary users are allowed to manage this API. The recommended value is no

IPADDR: specify a fixed IP address for this interface, provided that BOOTPROTO should be static or none

NETMASK: sets the subnet mask corresponding to the IP address, such as 255.255.255.0

PREFIX: sets the number of digits of the network prefix of the IP address; for example: 24

GATEWAY: setting default gateway

DNS1: the address of the preferred DNS server points to

DNS2: the address of the alternate DNS server points to

DNS3: the address of the third DNS server points to

PEERDNS: whether the address of the DNS server obtained from the DHCP server is allowed to point to the address that replaces the DNS server in this configuration file; the default value is allow

NM_CONTROLLED: whether to allow the NetworkManager service to manage the network interface; this service is very imperfect in CentOS6, so it is not recommended to use this service to manage the network interface; and it is best to turn this service off permanently by executing the following two commands

# service NetworkManager stop

# chkconfig NetworkManager off

Configuration file for hostname: / etc/sysconfig/network

HOSTNAME: the host name used by the current Linux system

# hostname View the FQDN of the current system

# hostname NEW_HOSTNAME

Log in again after logging out, and it will take effect.

CentOS7 and CentOS are basically the same, with the following additions:

UUID: a globally unique identifier that uniquely identifies this network interface

NAME: the display name of this network interface

DEFROUTE: whether to allow this network interface to run a default route

Four: Bonding-binding

Bonding-binding is to bind multiple network cards (multiple network interface devices) to the same IP address to provide network services; load balancing or high availability technology can be achieved between these network cards; through bonding, a virtual network card provides services and network connections, and all physical network cards are modified to the same MAC address

There are three working modes of Bonding:

Mode 0Mel-load balancing solution whose load balancing algorithm is balance-rr (round robin, polling); polling strategy means that packets are sent sequentially on each slave interface from beginning to end; this mode provides load balancing and fault tolerance

Mode 1Mel-active / standby solution, (active-backup, master-backup), in this mode, only one slave is activated for normal data transmission, while other interfaces monitor the working status of this interface; when and only if the active slave interface fails, one of the other backup interfaces is selected for activation; this mode can only achieve fault tolerance, not load balancing.

Mode 3Mel-full broadcast solution that transmits all messages over all slave interfaces

Miimon is used for link monitoring. If miimon=100, the system monitors the status of the link connection every 100ms; if a network interface is not connected in the miimon, it performs fault switching

When using Bonding, we need to configure:

1. Create a virtual interface

two。 Select the monitoring time of miimon and the working mode of Bonding

3. Select the physical interface for this Bonding

You can specify the properties of Bonding in the / etc/sysconfig/network-scripts/ifcfg-bond0 file:

DEVICE=bond0

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=none

BONDING_OPTS= "miimon=100 mode=0"

IPADDR=172.16.100.135

PREFIX=16

Modify the configuration file of the physical network card: / etc/sysconfig/network-scripts/ifcfg-eth2

DEVICE=eth2

BOOTROTO=none

MASTER=bond0

SLAVE=yes

USERCTL=no

Modify the configuration file of the physical network card: / etc/sysconfig/network-scripts/ifcfg-eth3

DEVICE=eth3

BOOTROTO=none

MASTER=bond0

SLAVE=yes

USERCTL=no

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report