一、什么是ip address
ip是由32个01组成的:
11111110.11111110.11111110.11111110=254.254.254.254
IP ADDRESS:internet protocol ADDRESS ##### 网络进程地址
ipv4 internet protocol version 4
二、子网掩码
作用: 用来划分网络区域,对网络位和主机位进行标识。可以相互通信的两个主机子网掩码一致。
区分: 子网掩码非0的位对应的ip上的数字表示这个ip的网络位,子网掩码0位对应的数字是ip的主机位;网络位表示网络区域,主机位表示网络区域里某台主机
三、ip通信判断
网络位一致,主机位不一致的2个IP可以直接通讯
172.25.254.1/24 24=255.255.255.0
172.25.254.2/24
172.25.0.1/16
四、网络设定工具
ping ####检测网络是否通畅
ping -c 1 ####次数
ping -w 1 ####时间
ifconfig ####查看或设定网络接口
ifconfig device ip/24 ##临时设定ip,device为网卡名称
ifconfig device down ##关闭网卡
ifconfig device up ##开启网卡
ip addr ####检测或指定网络接口
ip addr show ####检测
ip addr add ip/24 dev device ##设定
ip addr del dev eth0 ip/24 ##删除
ip addr flush eth0 ###更改ip步骤
ip addr add ip/24 dev device
注意:
1. device(网卡名字)的名字是一个物理事实,看到什么名字只能用什么名字
2. linux设定所有要想长久必须在配置文件
五、图形方式设定ip
nm-connection-editor ####修改后不生效
- 输入命令nm-connection-editor,得到下图:
- 点击add,然后点击create创建一个新的id,在Ethneter下设置名字,并选择网卡,如下图所示:
- 在IPv4 Settings下设置Method为Manual,然后添加地址,子网掩码设为24位,网关不设,但须点击一下,最后点击save保存。
- 完成设置以后如下所示:
systemctl stop NetworkManager ####关闭NetworkManager服务
systemctl restart network ####重启网络
ifconfig eth0 ###再次查看生效
systemctl start NetworkManager ####开启NetworkManager服务
六、nmtui方式设定ip
- 输入命令nmtui,点击回车,得到下图:
- 点击回车得到下图(以太网下面的gaogao是用图形方式建立的,可删除)
- 点击add后出现下图所示,选择以太网(Ethernet),再点击create
- 操作上面的步骤得到下图,设置一个名字,在Device处填写设备eth0/eth1,点击IPv4右侧的Automatic,选择Manual;再点击右边的show,设置ip,网关等(操作和图形方式一样),最后点击ok
- 完成所有操作,hhh添加成功,如下图所示:
注意:以上所有过程只能键盘操作,不能鼠标选择
七、命令方式设定网络
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.100/24 ###添加一个名字为westos,ip为172.25.254.100,子网掩码为255.255.255.0的以太网
修改为动态的网络:
nmcli connection modify westos ipv4.method auto 将静态网络更改成动态网络并进行查询
nmcli connection modify westos ipv4.method manual 将动态网络修改成动态网络并使配置立即生效
nmcli connection modify westos ipv4.addresses 172.25.254.200/24 命令给网络加ip地址
直接设定动态网络:
nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes
systemctl restart network
ifconfig
注意:nmcli 命令在使用时,NetworkManager必须开启