1.什么是IP ADDRESS
internet protocol ADDRESS ##网络进程地址
ipv4 internet protocol version 4
2x32 ip是由32个01组成
11111111.11111111.11111111.11111111=255.255.255.255
2.子网掩码
用来划分网络区域
子网掩码非0的位对应的ip上的数字表示这个ip网络位
子网掩码0位对应的数字是ip的主机位
网络位表示网络区域
主机位表示网络区域里某台主机
3.ip通信判定
网络位一致,主机位不一致的2个ip可以直接通讯
172.25.254.1/24 24=255.255.255.0
4.网络设定工具
ping ##检测网络是否通畅
ifconfig ##查看或设定网络接口
ifconfig device ip/24 ##设定
例:设定ip为172.25.254.29 ,子网掩码变为255.255.0.0
ifconfig device down ##关闭
ifconfig device up ##开机
ip addr ##查看或设定网络接口
ip addr show ##查看网络接口
ip addr add ip/24 dev device ##设定
例:设定ip为:172.25.254.129
添加ip:172.25.254.229
删除ip:172.25.254.229
ip addr flush eth0 ##更改ip
清空ip:
ip addr add ip/24 dev device
5.图形方式设定ip
1.nm-connection-editor
systemctl stop NetworkManager
systemctl restart network
systemctl start NetworkManager
2.nmtui
例:设定网络ip为172.25.254.129
具体操作如下:
查看网络ip设定成功
6.命名方式设定网络
nmcli | NetworkManager必须开启 |
---|---|
nmcli device connect eth0 | 启用eth0网卡 |
nmcli device disconnect eth0 | 关闭eth0网卡 |
nmcli device show eth0 | 查看网卡信息 |
nmcli device status eth0 | 查看网卡服务接口信息 |
nmcli connection show | 查看链接的信息 |
nmcli connection down westos | 关闭链接 |
nmcli connection up westos | 开启链接 |
nmcli connection delete westos | 删除链接 |
nmcli connection add type ethernet con-name westos ifname eth0 ip4 172.25.254.129/24 | 添加地址 |
nmcli connection modify westos ipv4.method auto | |
nmcli connection modify westos ipv4.method manual | 工作方式改为静态 |
nmcli connection modify westos ipv4.addresses 172.25.254.229/24 |
例:启用eth0网卡
例:关闭eth0网卡
nmcli device show eth0 查看网卡信息
nmcli device status eth0 查看网卡服务接口信息
nmcli connection show 查看链接的信息
nmcli connection down eth0 关闭链接
nmcli connection up westos 开启链接
nmcli connection delete westos 删除链接
例:网络静态变为动态
(1)添加网络地址 172.25.254.129
(2)切换到/etc/sysconfig/network-scripts/目录下,重启网络,查看网路ip是否为172.25.254.129
(3)nmcli connection modify haha ipv4.method auto将工作方式改为动态,查看ifcfg-haha文件内容
(4)重启网络后ifconfig查看,网络变为动态
例:网络由动态变为静态
(1)编辑ifcfg-haha文件内容,注释掉之前的地址,重启网络后ifconfig查看
(2)nmcli connection modify haha ipv4.method manual 将网络改为静态,系统出现报错,地址不能为空,添加地址后再次查看文件内容
(3)nmcli connection modify haha ipv4.method manual 将网络改为静态,重启网络后ifconfig查看
7.管理网络配置文件
网络配置目录
/etc/sysconfig/network-scripts/
网络配置文件的命名规则
ifcfg-eth0
DEVICE=eth0 ##设备名称
BOOTPROTO=dhcp|static|none ##设备工作方式
ONBOOT=yes ##网络服务开启时自动激活网卡
IPADDR= ##IP地址
PREFIX=24 ##子网掩码
NETMASK=255.255.255.0 ##子网掩码
NAME= ##接口名称
示例:动态网络设定文件
vim/etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
NAME= westos
systemctl restart network ##重启网络
ip addr show ##查看ip
示例:静态网络设定文件
vim/etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
IPADDR= 172.25.254.229
PREFIX=24
NAME= westos
systemctl restart network ##重启网络
ip addr show ##查看ip
具体操作如下:
示例:一块网卡配置多个ip
vim/etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
IPADDR0= 172.25.254.229
PREFIX=24
IPADDR1=192.165.0.129
NETMASK=255.255.255.0
NAME= westos
systemctl restart network ##重启网络
ip addr show eth0 ##查看ip
具体操作如下: