网络设置(ip命令使用)

新安装系统的服务器配置网络,有些不默认支持network的用第二种,(如:RockyLinux8.10)最小安装还没有dhcp客户端dhclient。

主要讲支持network服务的。

一. 配置网络

1.最基础的方法(支持network的如:centos)

①修改配置文件/etc/sysconfig/network-scripts/ifcfg-*

vim /etc/sysconfig/network-scripts/ifcfg-eth0

②修改配置文件里面的ONBOOT

ONBOOT=yes

③ 重启服务

systemctl  restart network

 

2.RockyLinux8.10配置网络

①修改配置文件/etc/sysconfig/network-scripts/ifcfg-*

vim /etc/sysconfig/network-scripts/ifcfg-eth0

②修改配置文件里面的ONBOOT

ONBOOT=yes

③ 重启服务

systemctl  restart NetworkManager

(上面如果不行,可以试试service NetworkManager restart)

 

3. 配置临时网络,不用修改ONBOOT=yes,直接有网络

①添加临时网络

ip add add 192.168.206.250/24 dev eth0

②启动网卡(不用启动别的网络服务)

ifup eth0 

或者

ip link set eth0 up

 

 

 

二. ip命令

1. 临时开启关闭网卡命令

开启 : ifup eth0     (或者 ip link set eth0 up)

关闭:ifdown eth0   (或者 ip link set eth0 down)

 

2.查看网卡流量

ip -s link

 

3.查看网卡所有信息(ip地址)

ip a

 

4. 查看路由

ip  r   (也就是ip route)

 

5.添加、删除路由

添加路由

#192.168.206.0的网关为192.168.206.1,通过eth0 找192.168.206.1设备访问192.168.206.0/24

ip route add 192.168.206.0/24 via 192.168.206.1 dev eth0  

删除路由

ip route del 192.168.206.0/24

 

5.添加/删除临时ip (第一个add可写成addr,address)

添加ip

ip add add 192.168.206.250/24 dev eth0

删除ip

ip add del 192.168.206.250/24 dev eth0

清空网卡所有ip地址

ip add 

 

posted @   铿锵有力自信且坚定  阅读(120)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
点击右上角即可分享
微信分享提示