网络的设定

1.常用网络协议ipv4

ip:

32          2进制
11111110.11111110.11111110.11111110 ==254.254.254.254

netmask:
用来表示ip的网络位和主机位
网络位表示网络区域
主机位表示网络区域中的某台主机

netmask非0位所对应的ip地址数值位这个ip的网络位
netmask 0位所对应的数值位这个ip的主机位

网络位一致主机位不同的两个ip是可以直接通信的
这样的两台主机叫做直连网络

2.设定ip

方法1
ifconfig  device  ip netmask 255.255.255.0

ifconfig  eth0     172.25.254.100  netmask  255.255.255.0

网络的设定

这样的设定是临时的,网络重启后失效

网络的设定


方法2

nm-connection-editor           图形的设定ip的方式

网络的设定

nmtui                          当系统没有图形时可以用此命令开启网络设定的UI界面

网络的设定

网络设备设定ip的方式有两种

DCHP     动态获取,ip不固定

static   静态ip为操作者自行设定,ip固定

网络的设定


在此图形工具中选择manual为静态网络,ip必须手动输入

选择DHCP为动态网络,随机给出

网络的设定


方法3
【格式】nmcli device ......
nmcli device status eth0     显示eth0的状态
nmcli device show eth0       显示eth0的详细信息
nmcli device disconnect  eth0    关闭链接

nmcli device connect  eth0       开启链接

网络的设定


【格式】nmcli connection ......
nmcli connection down westos    关闭网络链接名称位westos的链接
nmcli connection up   westos    开启

nmcli connection show westos    显示信息

网络的设定

nmcli connection delete westos  删除
nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes   建立动态网络
nmcli connection add type ethernet con-name westos ifname eth0 ipv4 172.25.252.101/24   建立静态网络


systemctl status NetworkManager        ##此工具会记住你的ip,可能导致设置失败   
systemctl stop NetworkManager
systemctl start NetworkManager

查看ip的方法
ifconfig eth0
ip addr show eth0
网络的设定

动态ip和静态ip的相互切换
DHCP(动态)-->static(静态)
nmcli connection modify westos ipv4.addresses 172.25.254.100/24
nmcli connection modify westos ipv4.method manual
systemctl restart network
static(静态)-->DHCP(动态)
nmcli connection modify westos ipv4.method auto
systemctl restart network
更改ip
nmcli connection modify westos ipv4.addresses 172.25.254.201/24

systemctl restart network

网络的设定网络的设定