Linux 基础(4) - 设置静态IP

1. ifconfig命令

1.1 输入ifconfig提示command not found。

今天安装了CentOS7,选择的是最小化模式,安装完成后,输入ifconfig提示command not found(未找到命令),吃了一惊。
解决方法:
1)找到ifconfig命令所在的软件包

yum search ifconfig

2)安装net-tools软件包

yum -y install net-tools

1.2 ifconfig 命令

用来配置网络或显示当前网络接口的状态

1.3 ifconfig 临时修改IP地址

ifconfig 网卡名称 IP地址 ---直接修改网卡的IP地址,(重启后失效)

ifconfig eth0 192.168.0.250

1.4 ifconfig 多个临时IP地址

多个临时ip,ifconfig 网卡名:0 第一个ip

ifconfig eth0:0 192.168.0.238
ifconfig eth0:1 192.168.0.250

1.5 删除临时IP地址

ifconfig 网卡名:0 del 192.168.0.250

ifconfig eth0:0 del 192.168.0.238
ifconfig eth0:1 del 192.168.0.250

2.修改静态IP

2.1 通过nmtui修改

1). 输入nmtui命令,并打开TUI界面

nmtui


2). 选择要编辑的网卡并选中Edit,回车进入编辑界面

3).将IPv4地址选择为手动,并编辑网管、DNS等信息(注意:一定要移动光标到最右下角的OK,回车保存

4).返回主界面后,选择激活链接

5).选择要激活的网卡并选中右侧,回车保存。

6).重启网络服务

systemctl restart network    (centos7)
service network restart      (centos6)

2.2 通过网卡修改配置文件改IP地址

1). 输入vim命令,打开ifcfg-eth0

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

2). 修改为静态IP,并设置IP相关信息。
BOOTPROTO=ONE, dhcp 表示动态获取IP,static 表示静态ip,none表示不指定,就是静态IP

3). 重启网络服务,ping www.baidu.com 测试网络

posted @ 2021-07-26 09:36  自然有道  阅读(1681)  评论(0编辑  收藏  举报