debian固定ip
前言
安裝好的Debian系統后,為了確保每次登陸的ip不變,需要固定
方法
命令如下
ip addr | grep inet
因為有有線網和無線網 2 種連接方式,因此需要區別。
其中 enp 的是有線,wlp 的是無線
查看網關 IP
命令如下
ip route show
結果如下
default via 192.168.48.1 dev enp3s0 onlink
default via 192.168.48.1 dev enp3s0 proto dhcp src 192.168.54.220 metric 100
default via 192.168.24.1 dev wlp28s0 proto dhcp src 192.168.25.166 metric 600
192.168.24.0/22 dev wlp28s0 proto kernel scope link src 192.168.25.166 metric 600
192.168.48.0/21 dev enp27s0 proto kernel scope link src 192.168.54.220 metric 100
192.168.54.0/24 dev enp27s0 proto kernel scope link src 192.168.54.220
其中 enp 的行就是有線網的網關 IP,wlp 的行是無線網的網關 IP
設置網絡文件
命令如下
sudo vim /etc/network/interfaces
修改成如下結果
# The loopback network interface
auto lo
auto enp3s0 # 有線網名字
iface lo inet loopback
allow-hotplug enp3s0 # 有線網名字
iface enp27s0 inet static # 有線網名字
address 192.168.0.57 # 要固定的 IP
netmask 255.255.254.0
gateway 192.168.0.1 # 網關地址 IP
dns-nameservers 8.8.8.8 8.8.4.4 #dns解析
啟動設定
命令如下
sudo /etc/init.d/networking restart
結果顯示
Restarting networking (via systemctl): networking.service