1.什么是IP ADDRESS
-
internet protocol ADDRESS ##网络进程地址
-
ipv4------internet protocol version 4
-
1.2x32
ip是由32个01组成
11111110.11111110.11111110.11111110.=254.254.254.254
注:网络设置范围:1~254,255广播位 -
eth0:以太网—对外开放的接口,网卡(网络数据传输方式)
lo:回环接口—内部传输接口(主机内部使用,安全)
2.子网掩码
172.25.254.21—255.255.255.0
子网掩码非0的位对应的ip上的数字表示这个ip的网络位
子网掩码0位对应的数字是ip的主机位
网络位表示网络区域
主机位表示网络区域里某台主机
3.ip通信判定
网络位一致,主机位不一致的2个IP可以直接通讯
172.25.254.1/24
其中24=255.255.255.0
测试172.25.254.xx同网段的2个IP可以ping通
4.网络设定工具
ping
##检测网络是否通畅
ping -c 1
##ping 1 次
ping -w 1
##等待1秒
ping -c1 -w1
##ping 1次等待1秒
ifconfig
命令
ifconfig
##查看或设定网络接口
ifconfig device ip/24
##临时设定IP
ifconfig device down
##关闭
ifconfig device up
##开启
ip addr
##检测或制定网络接口
ip addr show
##检测
ip addr add ip/24 dev device
##设定
ip addr del dev etho ip/24
##删除
更改ip步骤:
ip addr flush eth0 ##清空IP
ip addr add ip/24 dev device ##设置IP
注意:drvice的名字是一个物理事实,看到什么名字只能用什么名字
5.图形方式设定
1)nm-connection-editor
##网络配置图形开关
systemctl stop NetworkManger ##关闭网络管理者
systemctl restart network ##重启网络
systemctl start NetworkManager ##开启网络管理者
注:若重启后网络更改未生效,则systemctl stop NetworkManager
使用图形工具后,则systemctl start NetworkManager
2)nmtui ##文本界面
6.命令方式设定网络
nmcli设置网卡
命令 | 作用 |
---|---|
nmcli | NetworkManager必须开启 |
nmcli device connect eth0 | 启用eth0网卡 |
nmcli device disconnect eth0 | 关闭eth0网卡 |
nmcli device show eth0 | 查看网卡信息 |
nmcli device status eth0 | 查看网卡服务接口信息 |
nmcli device connect eth0
启用eth0网卡
nmcli device disconnect eth0
关闭eth0网卡
nmcli device status eth0
查看网卡服务接口信息
动静态网络分配
命令 | 作用 |
---|---|
nmcli connection show westos | 显示链接名为westos的网络信息 |
nmcli connection down westos | 关闭链接名为westos的网络 |
nmcli connection up westos | 开启链接名为westos的网络 |
nmcli connection delete westos | 删除链接名为westos的网络 |
nmcli connection add type ethernet con-name westos ifname eth0 ip4 172.25.254.121/24 | 添加网络 |
nmcli connection modify westos ipv4.method auto | 更改westos用户网络为动态 |
nmcli connection modify westos ipv4.method manual | 更改westos用户网络为静态 |
nmcli connection modify westos ipv4.adresses 172.25.254.221/24 | 更改westos用户IP |
注:静态改称动态:没有阻拦,动态改成静态:前提必须设置过ip,(nmcli connection modify westos ipv4.addresses 172.25.254.200/24)
7.管理网络配置文件
vim /etc/sysconfig/network-scripts/
网络配置文件的命名规则 ifcfg-xxxx
DEVICE=eth0 ##设备名称
BOOTPROTO=dhcp|static|none ##设备工作方式
ONBOOT=yes ##网络服务开启时自动激活网卡
IPADDR=172.25.254.21 ##IP地址
PREFIX=24 ##子网掩码
NETMASK=255.255.255.0 ##子网掩码
NAME=westos ##接口名称
示例:
静态网络设定文件
vim /etc/sysconfig/network-scripts/ifcfg-eth0
编写网络信息
systemctl restart network
重启网络,使更改生效
一块网卡上配置多个IP
vim /etc/sysconfig/network-scripts/ifcfg-eth0
编写网络配置信息
systemctl restart network
重启网络,使更改生效