1. Common network protocol ipv4
#ip:
32-bit binary
11111110.11111110.11111110.11111110 == 254.254.254.254
#netmask:
The network used to mark the real ip is the host bit. The
network bit represents the network area and the
host bit Indicates that
the ip address value corresponding to a non-zero bit of netmask of a host in the network area is the ip address value corresponding
to the netmask 0 bit of this ip. The host bit of this ip
When the network bits are consistent and the host bits are inconsistent, two IPs can communicate directly. Such two hosts are called directly connected networks.
2. Set ip
##Method 1: (temporarily set ip, id will change after restart)
ifconfig device ip netmask 255.255.255.0
ifconfig etho 172.25.254.100 netmask 255.255.255.0
##Method 2:
nm-connection-editor Graphical way to set ip
nmtui When the system has no graphics, you can use this command to open the ui interface for network settings
NEXT:DHCP #Dynamic acquisition, ip is not fixed
static #Static ip is set to operate the font, ip is fixed
# Select DHCP as dynamic network
in this graphic tool # Select manual as static network in this graphic tool, ip needs to be manually entered
###ip set on the network device# ##
Note: ping 172.25.254.250 to see if the network is connected
##Method 3:
nmcli device status eth0 #View eth0 status
nmcli device show eth0 #View eth0 details
nmcli device disconnect eth0 #Close eth0 network
nmcli device connect eth0 #Open eth0 network
**nmcli connection.....
down xxxx close xxxx network
up xxxx open xxxx network
delete xxxxx delete xxxx network
show xxxx display network information
nmcli connection add type ethernet con-name westos (set whatever) ifname eth0 (network card) autoconnect yes ##set dynamic ip##
nmcli connection add type ethernet con-name westos ifname eth0 ip4 172.25.254.120/24##set static ip##
Method 4:
cd /etc/sysconfig/network-scripts/
vim ifcfg-xxxx
DEVICE=NIC
ONBOOT=yes
BOOTPROTO=dhcp | none|static
IPADDR=ip
NETMASK=subnet mask |PREFIX=subnet mask abbreviation
NAME=name "Optional"
Restart the service
##A static network card sets multiple ips
DEVICE=eth0
ONBOOT=yes BOOTPROTO
=none
IPADDR0=172.25.254.120
PREFIX0=24
IPADDR1=172.25.0.120
PREFIX1=24
NAME=WESTOS
systemctl restart network
ip addr show eth0 ##View
##File parameter documentation: /usr/share/doc/initscripts-*/sysconfig.txt
3. How to change the network? (A network ip is required)
(1)dhcp---->static dynamic to static
nmcli connection modify westos ipv4.addresses 172.25.254.100/24
nmcli connection modify westos ipv4.method manual
systemctl restart network
(2)static--- ->dhcp static to dynamic
nmcli connection modify westos ipv4.method auto
restart service
(3) change ip
nmcli connection modify westos ipv4.addresses 172.25.254.220.24
restart service
##systemctl stop NetworkManager.service close network management service
##systemctl start NetworkManager.service opens the network management service
4. Set gateway
####Operate on real machine####
[kiosk@foundation20 Desktop]$ su - root ##Switch to super user
Password: westos
Last login: Sun Apr 15 15:39:02 CST 2018 on pts /2
[root@foundation20 ~]# route -n ##View gateway
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.25.254.254 0.0.0.0 UG 425 0 0 br0
172.25.20.0 0.0.0.0 255.255. 255.0 U 425 0 0 br0
172.25.254.0 0.0.0.0 255.255.255.0 U 425 0 0 br0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[root@foundation20 ~]# vim /etc/sysconfig/network-scripts/ifcfg-br0 ###Edit the configuration file to delete GATEWAY=XXXXXXX
[root@foundation20 ~]# systemctl restart network ###Restart the service
[root@foundation20 ~ ]# ifconfig ###Check the ip of this machine, that is, the ip of this machine is the gateway.
br0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.25.254.20 netmask 255.255.255.0 broadcast 172.25.254.255
inet6 fe80:: 221:ccff:fec7:d381 prefixlen 64 scopeid 0x20<link>
ether 00:21:cc:c7:d3:81 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s25: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 00:21:cc:c7:d3:81 txqueuelen 1000 (Ethernet)
RX packets 403645 bytes 313990285 (299.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 104388 bytes 7998305 (7.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 20 memory 0xf2500000-f2520000
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 569149 bytes 226049238 (215.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 569149 bytes 226049238 (215.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 00:00:00:00:00:00 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:22:2f:b3 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0-nic: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:9c:a9:ff txqueuelen 500 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp3s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 8c:70:5a:bc:07:90 txqueuelen 1000 (Ethernet)
RX packets 876 bytes 70889 (69.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 26 bytes 5297 (5.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@foundation20 ~]# route -n ###查看一下网关没有了
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.25.20.0 0.0.0.0 255.255.255.0 U 425 0 0 br0
172.25.254.0 0.0.0.0 255.255.255.0 U 425 0 0 br0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[root@foundation20 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.43.1 0.0.0.0 UG 600 0 0 wlp3s0
172.25.20.0 0.0.0.0 255.255.255.0 U 425 0 0 br0
172.25.254.0 0.0.0.0 255.255.255.0 U 425 0 0 br0
192.168.43.0 0.0.0.0 255.255.255.0 U 600 0 0 wlp3s0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[root@foundation20 ~]# ping www.baidu.com ###ping一下百度看通不通
PING www.a.shifen.com (220.181.111.188) 56(84) bytes of data.
64 bytes from 220.181.111.188: icmp_seq=1 ttl=53 time=70.4 ms
64 bytes from 220.181.111.188: icmp_seq=2 ttl=53 time=76.0 ms
64 bytes from 220.181.111.188: icmp_seq=3 ttl=53 time=38.0 ms
64 bytes from 220.181.111.188: icmp_seq=4 ttl=53 time=44.0 ms
64 bytes from 220.181.111.188: icmp_seq=5 ttl=53 time=43.9 ms
64 bytes from 220.181.111.188: icmp_seq=6 ttl=53 time=48.6 ms
64 bytes from 220.181.111.188: icmp_seq=7 ttl=53 time=45.5 ms
64 bytes from 220.181.111.188: icmp_seq=8 ttl=53 time=38.1 ms
64 bytes from 220.181.111.188: icmp_seq=9 ttl=53 time=40.6 ms
64 bytes from 220.181.111.188: icmp_seq=10 ttl=53 time=47.7 ms
^C
--- www.a.shifen.com ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9013ms
rtt min/avg/max/mdev = 38.095/49.342/76.086/12.503 ms
[root@foundation20 ~]# systemctl start firewalld ##打开防火墙
[root@foundation20 ~]# firewall-cmd --add-masquerade ##Open SND function
success
###In the virtual machine ###
vim /etc/sysconfig/network ##Enter the ip of the real machine settings
GATEWAY=172.25.254.120
systemctl restart network ##Restart the service
vim /etc/resolv.conf ##Write nameserver= 172.25.254.120
ping www.baidu.com ##Internet
##Troubleshooting##
1. Can the real machine go online ping www.baidu.com
2.firewalld-cmd --list-all -->yes
3. Look at the ip gateway dns
ping gateway in the virtual machine
4.vim /etc/sysctl.conf ##Kernel routing open
ip_forward = 1
sysctl -p
5. virt-manager ##Delete the network card -> delete the bad network card first -> use add to create a new network card