ipv4
2.进制32位—-10进制
172.25.0.10/255.255.255.0
172.25.0.10:ip地址
255.255.255.0:子网掩码
子网掩码255位对应的ip位为网络位
子网掩码0对应的ip位为主机位
设置ip
图形化设置
1.图形界面
nm-connection-editor

运行此命令后,会出现图形界面

进入后,选择dhcp为动态ip设置

动态ip
选择manual可设置静态ip

静态ip

2.文本化ip设置
nmtui

进入后按tab健可选择
device填写eth0

选择Automatic可设置动态ip

动态ip
device同样填写eth0

选择manual
地址填写172.25.254.101/24
可设置静态ip

3.临时设置ip(重启后失效)
ifconfig device ip netmask 255.255.255.0
ifconfig eth0 172.25.254.11 netmask 255.255.255.0

重启后
systemctl restart network(重启)
可见重启后ip变为172.25.254.101

4.nmcli设置
nmcli device status 显示 eth0 状态
nmcli decice show 显示eth0详细信息

nmcli device disconnect eth0关闭eth0

nmcli device connect eth0 打开eth0

nmcli connection ....
nmcli connection down hello 关闭

nmcli connection up hello 打开

nmcli connection show hello 查看详细信息

nmcli connection delete hello 删除

nmcli connection add type ethernet con-name hello ifname eth0 autoconnect yes 设置动态ip

nmcli connection add type ethernet con-name hello ifname eth0 ip4 172.25.254.101/24 设置静态ip

static--------->dhcp静态到动态
nmcli connection modify hello ipv4.method auto

systemctl restart network
dhcp------>static更改动态网络到静态
nmcli connection modify hello ipv4.addresses 172.25.254.101/24
nmcli connection modify hello ipv4.method manual
systemctl restart network

更改ip
nmcli connection modify hello ipv4.addresses 172.25.254.102/24
systemctl restart network

5.编辑配置文件
cd /etc/sysconfig/network-scripts/
vim ifcfg-xxxx

DEVICE=网卡
ONBOOT=yes
BOOTPROTO=dhcp| none|static
IPADDR=ip
NETMASK=子网掩码|PREFIX=子网掩码缩写
[NAME=连接名称]
DHCP动态
cd /etc/sysconfig/network-scripts/
vim ifcfg-hello

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp

systemctl restart network

静态网络
cd /etc/sysconfig/network-scripts/
vim ifcfg-hello

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.136
NETMASK=255.255.255.0 | PREFIX=24


systemctl restart network


一个静态网卡设置多个ip
cd /etc/sysconfig/network-scripts/
vim ifcfg-hello
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
IPADDR0=172.25.254.136
PREFIX0=24
IPADDR1=172.25.0.136
PREFIX1=24
systemctl restart network
ip addr show eth0

网关
1.网关
路由器上和自己处在同一个网段的那个ip
2.设定网关
systemctl stop NetwrokManager

vim /etc/sysconfig/network ##全局网关
GATEWAY=网关ip

vim /etc/sysconfig/network-scripts/ifcfg-网卡配置文件 ##网卡接口网关
GATEWAY=网关ip

systemctl restart netwrok

route -n ##查询网关
ping
ping真机ip

智能解析
vim /etc/resolv.conf
在里面加
nameserver 114.114.114.114

真机:切换超级用户 --> 进行网关设置 --> 重启网络 --> 连接 wifi--> 查看网关 -->ping www.baidu.com
虚拟机:设置网关 --> 重启网络 -->DNS--> 查看网关 -->ping www.baidu.com
本文介绍了Linux系统中网络配置的各种方法,包括IPv4设置、静态IP与动态IP的转换、图形化与命令行配置IP,以及如何通过nmcli工具管理网络连接。此外,还详细讲解了网关的设定与查询,并提到了DNS解析的配置步骤。

60万+

被折叠的 条评论
为什么被折叠?



