Linux: Network Settings

1. Network settings
1. Common network protocol ipv4
32 binary
11111110.11111110.11111110.11111110=254.254.254.254
 
netmask: used to mark the so-called network bit and host bit of real ip. The
network bit represents the network area and
the host bit represents a host in the network area.

The value of the ip address corresponding to the non-zero bits of the netmask is the network bit of the ip The value of the ip address corresponding to the netmask 0 bit is
the host bit of the ip. The two IPs whose

network bits are consistent and the host bits are inconsistent can communicate directly. The host is called a directly connected network


2. Set ip
method 1:
ifconfig device ip netmask 255.255.255.0

eg: ifconfig eth0 172.25.254.100 netmask 255.255.255.0 (This setting method is temporary and will fail after the network service is restarted)


Method Two:

The method of setting ip of nm-connection-editor graphics


nmtui This command can be used when the system has no graphics


There are two ways to set ip of network equipment:
dbcp dynamic acquisition, ip is not fixed
static ip is set by the operator, ip is

fixed Select dbop as dynamic network
in this graphic tool, select manual as static network in this graphic tool, ip must be entered manually

Method 3:
nmcli  
nmcli device status eth0 Display eth0 status
nmcli device show eth0 Display eth0 details
nmcli device disconnect eth0 Close
nmcli device connect eth0 Open

nmcli connection ....
nmcli connection down westos (link) Close
nmcli connection up westos open
nmcli connection show westos display
nmcli connection delete westos delete
nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes temporarily set ip (dynamic network)
nmcli connection add type ethernet con-name westos ifname eth0 ip4 172.25.254.100/24 ​​Static network There is

already a connection that needs to be changed ip
dbcp---->static Dynamic network is converted to static network
nmcli connection modify (link to follow) linux ipv4.addresses 172.25.254.119/24
nmcli connection modify linux ipv4.method manual
systemctl restart network restart

static--->dbcp static network to dynamic network
nmcli connection modify linux ipv4.method auto
systemctl restart network

change ip
nmcli connection modify linux ipv4.addresses 172.25 .254.119/24
systemctl restart network

Method 4:
delete the previous ip before doing it, use nmcli connection delete westos command to delete
cd /etc/sysconfig/network-scripts/
vim ifcfg-xxxx (write whatever)
DEVICE=network card
ONBOOT=yes
BOOTPROTO=dbcp|none|static
IPADDR=ip
NETAMASK=subnetmask|PREFIX=subnetmask abbreviation
[NAME=link name] can be added or not

Dynamic network:
cd /etc/sysconfig/network-scripts/
vim ifcfg-linux
DEVICE=NIC(eth0)
ONBOOT=yes
BOOTPROTO=dbcp

systemctl restart network

Static network (single):
cd /etc/sysconfig/network-scripts/
vim ifcfg-linux
DEVICE=NIC(eth0)
ONBOOT=yes
BOOTPROTO= none
IPADDR=ip
NETAMASK=172.25.254.119
PREFIX=24

systemctl restart network

A static network card sets multiple ips:
cd /etc/sysconfig/network-scripts/
vim ifcfg-linux
DEVICE=network card (eth0)
ONBOOT=yes BOOTPROTO
=none
NETAMASK0=172.25.254.119
PREFIX0=24
NETAMASK1=172.25.254.119
PREFIX1=24

systemctl restart networkv
ip addr show eth0

file parameter documentation: /usr/share/doc/initscripts-*/sysconfig.txt


2. gateway gateway

1.
The main function of the router is to use as nat dnat
destination address translation
snat source address translation

2.
The ip on the gateway router that is in the same network segment as itself

3. Set the gateway
systemctl stop NetwrokManager
vim / etc/sysconfig/network global gateway
GATEWAY=gateway ip

vim /etc/sysconfig/network-scripts/ifcfg-network card configuration file network card interface gateway
GATEWAY=gateway ip

systemctl restart netwrok

route -n query gateway

search result:

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 (Gateway) 172.25.0.254 0.0.0.0 UG 0 0 0 eth0
172.25.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0



three.dns
1.dns
dns It is a server
. This server provides the function of answering the corresponding relationship between the client's host name and ip.

2. Set dns
vim /etc/resolv.conf
nameserver dns server ip
nameerver 114.114.114.114 The system does not know, you need to ask

vim /etc/hosts
for input : ip URL system knows

vim /etc/sysconfig/network-scripts/ifcfg-network card configuration file
DNS1=dns server ip

3. Local resolution file
vim /etc/hosts
ip host name

4. Local resolution file and dns read priority Adjust
/etc/nsswitch.conf
 38 #hosts: db files nisplus nis dns
 39 hosts: files dns ##files stands for local parsing files, dns stands for dns server, the one in front is the priority

4. Gateway troubleshooting
1. Real machine ping www.baidu.com
firewalld-cmd --list-all -->yes
see ip, gateway, dns
ping gateway

network card in the virtual host: virt-manager

vim/etc/sysctl.conf
ip_forward = 1
sysctl -p




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325449106&siteId=291194637