网络多方法多模式设置及网关配置

本文介绍了Linux系统中网络配置的各种方法,包括IPv4设置、静态IP与动态IP的转换、图形化与命令行配置IP,以及如何通过nmcli工具管理网络连接。此外,还详细讲解了网关的设定与查询,并提到了DNS解析的配置步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值