网络设定
1.常用网络协议IPV4网络
ip:
32位 2进制
11111110.11111110.11111110.11111110=254.254.254.254
netmask:(子网掩码)
用来标识ip的网络位和主机位
网络位表示网络区域
主机位表示网络区域中的某台主机。
netmask非0位所对应的ip地址数值位这个ip的网络位。
netmask0位所对应的ip地址数值位这个ip的主机位。
网络位一致主机位不一致的两个ip是可以直接通信的,这样的两台主机叫做直连网络。
2.设定ip
方法一:
ifconfig device ip netmask 255.255.255.0
例如:ifconfig eth0 172.25.254.114 netmask 255.255.255.0
这样的设定是临时的,在网络服务重新启动后失效。
方法二:
nm-connection-editor 图形界面设定ip的方法
nmtui 当系统没有图形时可以用此命令设定
例如:用nm-connection-editor设定ip为:172.25.254.117
网络设备设定ip的方式有两种:动态,静态。
dhcp 动态获取,ip不固定
static 静态ip是操作着自行设定,ip固定
在此图形工具中选择dhcp为动态网络
在此图形工具中选择manual 位静态网络,ip须手动输入
如图:

方法三:
nmcli
nmcli device status eth0 查看设备状态
nmcli device show eth0 查看设备详细信息
nmcli device disconnect eth0 关闭
nmcli device connect eth0 开启
nmcli connection 。。。 服务链接
nmcli connection down westos 关闭westos链接
nmcli connection up westos 开启westos链接
nmcli connection show westos 查看westos链接详细信息

nmcli connection delete westos 删除westos链接

nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes
添加 类型 以太网 链接名称 名称 网卡类型 eth0 动态
例如:nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes
添加eth0的动态网络


添加静态westos链接
nmcli connection add type ethernet con-name westos ifname eth0 ip4 172.25.254.171
添加 类型 以太网 链接名称 名称 网卡类型 eth0 网络类型 ip地址
添加静态westos链接
如图:
更改链接信息类型:
dhcp-----static 动态改为静态:
1.nmcli connection modify westos ipv4.addresses 172.25.254.200/24
2.nmcli connection modify westos ipv4.method manual
3.systemctl restart network

static-----dhcp 静态改为动态:
1.nmcli connection modify westos ipv4.method auto
2.systemctl restart network
方法四:
cd /etc/sysconfig/network-scripts/
vim ifcfg-xxxx
DEVICE=网卡
ONBOOT=yes
BOOTRPOTO=dhcp或 none=static
IPADDR=ip
NETMASK=子网掩码或PREFIX=子网掩码缩写
1.dhcp(动态):
cd /etc/sysconfig/network-scripts/
编辑文件vim ifcfg-westos 链接名称
内容为:
DEVICE=eth0 网卡名称
ONBOOT=yes 开机自动加载
BOOTRPOT=dhcp 网络类型(动态)
systemctl restart network 重启服务
2.静态网络:
cd /etc/sysconfig/network-scripts/
编辑文件vim ifcfg-westos 链接名称

内容为:
DEVICE=eth0 网卡名称
ONBOOT=yes 开机自动加载
BOOTRPOT=none 网络类型(静态)
IPADDR=ip ip地址
NETMASK=255.255.255.0或PREFIX=24 子网掩码

systemctl restart network 重启服务
一个静态网卡设定多个ip:
cd /etc/sysconfig/network-scripts/
编辑文件vim ifcfg-westos 链接名称
