文章目錄
一.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 新的連接