linux网络配置静态ip
一、centos设置静态IP
1.1 设置网络查看ip
启动centos启动 vi工具编辑 /etc/sysconfig/network-scripts/ifcfg-ens33
也可以如下配置:
vi 编辑器,按下 i 进入编辑模式,输入修改 ONBOOT=no ONBOOT=yes按下 Esc键进入命令模式,直接输入::wq
回车键退出
1.2设置静态ip
[root@localhost webrx]# ping mi.com
PING mi.com (58.83.160.156) 56(84) bytes of data.
64 bytes from 58.83.160.156 (58.83.160.156): icmp_seq=1 ttl=41 time=74.2 ms
64 bytes from 58.83.160.156 (58.83.160.156): icmp_seq=2 ttl=41 time=73.6 ms
64 bytes from 58.83.160.156 (58.83.160.156): icmp_seq=3 ttl=41 time=73.0 ms
64 bytes from 58.83.160.156 (58.83.160.156): icmp_seq=4 ttl=41 time=75.7 ms
64 bytes from 58.83.160.156 (58.83.160.156): icmp_seq=5 ttl=41 time=72.9 ms
^X^H^C
--- mi.com ping statistics ---
15 packets transmitted, 5 received, 66% packet loss, time 14321ms
rtt min/avg/max/mdev = 72.979/73.933/75.796/1.068 ms
[root@localhost webrx]# clear
[root@localhost webrx]#
[root@localhost webrx]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:ef:76:08 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.67/24 brd 192.168.1.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::c4ff:c725:8e7e:8168/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@localhost webrx]# ifconfig
bash: ifconfig: 未找到命令
[root@localhost webrx]# yum install net-tools -y
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.neusoft.edu.cn
* extras: mirrors.neusoft.edu.cn
* updates: mirrors.neusoft.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 net-tools.x86_64.0.2.0-0.25.20131004git.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
===================================================================================================================================
Package 架构 版本 源 大小
===================================================================================================================================
正在安装:
net-tools x86_64 2.0-0.25.20131004git.el7 base 306 k
事务概要
===================================================================================================================================
安装 1 软件包
总下载量:306 k
安装大小:917 k
Downloading packages:
net-tools-2.0-0.25.20131004git.el7.x86_64.rpm | 306 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : net-tools-2.0-0.25.20131004git.el7.x86_64 1/1
验证中 : net-tools-2.0-0.25.20131004git.el7.x86_64 1/1
已安装:
net-tools.x86_64 0:2.0-0.25.20131004git.el7
完毕!
[root@localhost webrx]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.67 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::c4ff:c725:8e7e:8168 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:ef:76:08 txqueuelen 1000 (Ethernet)
RX packets 2871 bytes 673875 (658.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1167 bytes 125736 (122.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 68 bytes 5908 (5.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 68 bytes 5908 (5.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost webrx]#
二、ubuntu设置静态IP
$ sudo vim /etc/netplan/00-installer-config.yaml
设置静态IP addresses即可