ubuntu下配置網路 IP 閘道器 DNS

2021-08-07 07:16:12 字數 1179 閱讀 6415

命令列下直接配置:

配置ip和子網掩碼:

ifconfig eth0 192.168.2.1 netmask 255.255.255.0
設定閘道器:

route add default gw 192.168.2.254
命令列下直接配置在機器重啟後就無效了,需要重新配置。要一直有效就需要改配置檔案進行配置

開啟配置檔案:/etc/network/inte***ces

配置檔案中已經有了lo本地回環網路的配置。再在後面加上自己要配置的網絡卡就可以了,下面這個例子是靜態ip的。如果是動態自動獲得ip那只要iface eth0 inet dhcp就可以了。

# inte***ces(5) file used by ifup(8) and ifdown(8)

auto lo

iface lo inet loopback

auto eth0

iface eth0 inet static

address 192.168.2.229

gateway 192.168.2.1

netmask 255.255.255.0

dns-nameservers 8.8.8.8

除此之外需要修改/etc/networkmanager/networkmanager.conf文件中的managed引數,使之為true。

配置dns的第二個方法

dns是在/etc/resolv.conf檔案下配置的,但是開啟這個檔案會看到這樣一段話:

# dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)

# do not edit this file by hand -- your changes will be overwritten

說這個檔案是動態建立的,任何修改都會被覆蓋。

所以,就需要修改/etc/resolvconf/resolv.conf.d/base檔案

在裡面加入nameserver 8.8.8.8,儲存完後會自動更新進resolv.conf裡

重啟網路的方法:/etc/init.d/networking restart

ubuntu下配置ip,掩碼,閘道器和DNS

一。通過命令設定ip,掩碼,閘道器和dns 1.設定網絡卡eth0的ip位址和子網掩碼 sudo ifconfig eth0 192.168.0.50 netmask 255.255.255.0 2.設定閘道器 sudo route add default gw 192.168.0.1 3.設定dn...

centos7下修改網路配置IP位址閘道器DNS等

root gaojingbo ip a 改變eth0 方法一 root gaojingbo vim etc sysconfig network scripts ifcfg eth0 靜態 手工 name eth0 連線名 device eth0 裝置名 bootproto none 啟動協議 sta...

ubuntu 下配置靜態ip

1.編輯相關檔案 sudo vim etc network inte ces 加入下面的配置 auto eth0 iface eth0 inet static address 192.168.0.117 gateway 192.168.1.1 這個位址你要確認下 閘道器是不是這個位址 netmask...