Linux发行版固定IP
程序员文章站
2022-06-25 09:23:41
先ping一下确保ip没被占用。确认下自己的网卡名字下面。ip addr如下面wlp2s0就是我的网卡名啦1: lo: 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 ....
- 先ping一下确保ip没被占用。
- 确认下自己的网卡名字下面。
ip addr
- 如下面wlp2s0就是我的网卡名啦
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: enxd43a6507a2c8: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether d4:3a:65:07:a2:c8 brd ff:ff:ff:ff:ff:ff
3: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether a0:c5:89:e2:c3:f9 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.106/24 brd 192.168.0.255 scope global dynamic noprefixroute wlp2s0
valid_lft 7002sec preferred_lft 7002sec
inet 192.168.0.100/24 brd 192.168.0.255 scope global secondary noprefixroute wlp2s0
valid_lft forever preferred_lft forever
inet6 fe80::404c:18d:7f1c:b4f9/64 scope link noprefixroute
valid_lft forever preferred_lft forever
- 下面是固定ip:192.168.0.100 的操作:
一、Ubuntu固定IP:
- 配置文件在 /etc/netplan 下,yaml文件:
cd /etc/netplan
- 修改配置文件内容为:
network:
version: 2
ethernets:
wlp2s0:
dhcp4: no
dhcp6: no
addresses: [192.168.0.100/24]
gateway4: 192.168.0.1
nameservers:
addresses: [114.114.114.114, 8.8.8.8]
禁用dhcp自动分配ip
键 | 描述 |
---|---|
addresses | 子网ip |
gateway4 | 网关地址 |
nameservers | dns服务器 |
- 应用配置生效
sudo netplan apply
- 查看ip
ip addr
二、Centos固定IP:
- 配置文件在 /etc/sysconfig/network-scripts 下,一般为 ifcfg-{网卡名}:
cd /etc/sysconfig/network-scripts
- 禁用dhcp协议,改为静态ip方式:
#BOOTPROTO="dhcp"
BOOTPROTO="static"
- 增加下面内容
IPADDR=192.168.0.181
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
DNS1=114.114.114.114
DNS2=8.8.8.8
键 | 描述 |
---|---|
IPADDR | 子网ip |
NETMASK | 子网掩码 |
GATEWAY | 网管地址 |
DNS1/DNS2 | dns服务器 |
- 应用配置生效
sudo service network restart
- 查看ip
ip addr
本文地址:https://blog.csdn.net/iamzhoujunjia/article/details/107350260