文章目录
一.ip的相关知识
1.inter proto address
2.协议名称: tcp/ip
3.协议版本: ipv4
4.ip地址 2^32
11111111.11111111.11111111.11111111 === 255.255.255.255
11111110.11111110.11111110.11111110 === 254.254.254.254
5.子网掩码:
ip地址:11111110.11111110.11111110.11111110
11111111.11111111.00000000.00000000 ==== 255.255.0.0
什么地方: 网络位
什么人: 主机位
什么样的两个ip可以通信?
网络位相同,主机位不同的两个ip是可以直接通信的
二.关于ip命令
1.ping命令
ping ##检测网络通畅
-c 1 ##只ping一次
-w 1 ##等待1s
[root@rhel7 ~]# ping -w1 -c1 172.25.254.30
PING 172.25.254.30 (172.25.254.30) 56(84) bytes of data.
64 bytes from 172.25.254.30: icmp_seq=1 ttl=64 time=26.9 ms
--- 172.25.254.30 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 26.989/26.989/26.989/0.000 ms
2.ifconfig
ifconfig device ip netmask
ifconfig ens33 172.25.254.99 netmask 255.255.255.0
3.ip addr
ip addr show ##显示ip
ip addr del dev ens33 172.25.254.99/24 ##删除ip
ip addr add 172.25.254.99/24 dev ens33 ##添加ip
三.更改IP的常用方式
1.图形方式(nm-connection-editor)
nm-connection-editor
1.图形方式打开
2.选择以太网
3.修改连接名为westos,选择设备
4.选择静态模式,并配置IP地址
5.查看配置是否成功
2.无图形界面(nmtui)
1.新建连接
2.选择以太网
3.配置IP
3.命令方式
nmcli device status ##查看设备状态
nmcli device disconnect ens33 ##关闭设备
nmcli device connect ens33 ##开启设备
nmcli connection show ##查看网卡信息
nmcli connection down westos ##关闭
nmcli connection up westos ##打开
nmcli connection modify westos ip4 172.25.254.88/24 ##添加ip,添加完成后必须要重启连接才能生效
nmcli connection delete westos # #删除连接
nmcli connection add con-name westos ifname ens33 type ethernet ip4
172.25.254.88/24 ##添加连接
connection add con-name westos ifname ens33 type ethernet ipv4.method auto ##添加dhcp网络
4.文件方式
配置目录:/etc/sysconfig/network-scripts/
配置文件:ifcfg-任意名称
dhcp:
vim /etc/sysconfig/network-scripts/ifcfg-westos
DEVICE=ens33 ##网卡名称
ONBOOT=yes ##网络服务启动网卡激活
BOOTPROTO=dhcp ##网卡工作模式为dhcp
NAME=westos ##连接名称为westos
##在rhel7:
systemctl restart network
##在rhel8中:
systemctl restart NetworkManager
nmcli connection down 旧的连接
nmcli connection up 新的连接
静态网络:
vim /etc/sysconfig/network-scripts/ifcfg-westos
DEVICE=ens33 ##网卡名称
ONBOOT=yes ##网络服务启动网卡激活
BOOTPROTO=none|static ##网卡工作模式为dhcp
NAME=westos ##连接名称为westos
IPADDR=172.25.254.200 ##IP地址
NETMASK=255.255.255.0 ##子网掩码
##在rhel7中:
systemctl restart network
##在rhel8中:
systemctl restart NetworkManager
nmcli connection down 旧的连接
nmcli connection up 新的连接