歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Debian下設置 IP 地址、網關、DNS

Debian下設置 IP 地址、網關、DNS

日期:2017/2/27 15:48:04   编辑:Linux教程
1、設置IP地址、網關
cp /etc/network/interfaces /etc/network/interfaces.bak # 備份原有配置文件
vi /etc/network/interfaces # 編輯網網卡配置文件

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0 # 開機自動連接網絡
allow-hotplug eth0
iface eth0 inet static # static表示使用固定ip,dhcp表述使用動態ip
address 192.168.21.166 # 設置ip地址
netmask 255.255.255.0 # 設置子網掩碼
gateway 192.168.21.2 # 設置網關

按 ESC 鍵,然後輸入 :eq 保存並退出。

下面的版本便於復制, 因為配置文件裡最好不要有中文:
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.21.166
netmask 255.255.255.0
gateway 192.168.21.1

2、設置dns
cp /etc/resolv.conf /etc/resolv.conf.bak # 備份原有dns配置文件
vi /etc/resolv.conf # 編輯配置文件
nameserver 127.0.0.1
nameserver 8.8.8.8 # 設置首選dns
nameserver 8.8.4.4 # 設置備用dns

按 ESC 鍵,然後輸入 :eq 保存並退出。

下面的版本便於復制, 因為配置文件裡最好不要有中文:
nameserver 127.0.0.1
nameserver 8.8.8.8
nameserver 8.8.4.4

3、重啟網絡
service networking restart # 重啟網絡
至此,IP地址、網關、DNS配置完成,現在系統已經可以上網了。
Copyright © Linux教程網 All Rights Reserved