ubuntu设置网卡默认启动_ubuntu 网络配置
檢查網(wǎng)絡(luò)配置命令:ifconfig
一、通過配置文件配置
新手沒怎么用過Ubuntu,所以走了不少彎路,網(wǎng)上找了很多方法,大都沒對我起到幫助作用,所以把自己的配置方法寫一寫。
Ubuntu上連了兩塊網(wǎng)卡,eth0為外網(wǎng)的eth1為內(nèi)網(wǎng)的(VPC的特點(diǎn),要和宿主機(jī)直接通訊必須組個內(nèi)網(wǎng))
eth0上IP為自動獲取
eth1上為手工設(shè)置(又是VPC自己要求的)
配置過程:
1、打開Ubuntu的/etc/network/interfaces文件 。默認(rèn)內(nèi)容如下:
auto lo
iface lo inet loopback
2、eth0為自動獲取IP,所以不需要配置了。插入要手工設(shè)置IP的eth1的IP信息,編輯后內(nèi)容如下,前面auto eth1,讓網(wǎng)卡開機(jī)自動掛載.:
auto lo
iface lo inet loopback
auto eth1
iface eth1 inet static
address 192.168.0.101
netmask 255.255.255.0
network 192.168.0.0
broadcask 192.168.0.255
gateway 192.168.0.2
hwaddress ether [your_mac_address] 讓網(wǎng)絡(luò)配置幫頂?shù)侥硰埼锢韒ac網(wǎng)卡上。
3、編寫完畢保存,然后打開終端運(yùn)行如下命令,重新啟動網(wǎng)卡即可:
$??? /etc/init.d/networking restart
也可以重啟網(wǎng)卡讓新配置生效,優(yōu)點(diǎn)是不影響其他網(wǎng)絡(luò)接口:
$ sudo ifdown eth0
$ sudo ifup eth0
4、如果以DHCP方式配置網(wǎng)卡,則改為:
auto eth0
iface eth0 inet dhcp
也可以在命令行下直接輸入下面的命令來獲取地址
sudo dhclient eth0
ubuntu server 14.04設(shè)置IP和DNS
設(shè)置IP:
vim /etc/network/interfaces
將以下內(nèi)容:
auto eth0
iface eth0 inet dhcp
修改為:
auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx
gateway xxx.xxx.xxx.xxx
hwaddress ether [your_mac_address] 讓網(wǎng)絡(luò)配置幫頂?shù)侥硰埼锢韒ac網(wǎng)卡上。
把xxx.xxx.xxx設(shè)置為你要個性的信息既可,其中
auto eth0? #開機(jī)自動連接網(wǎng)絡(luò)
iface eth0 inet static?? #static表示使用固定ip,dhcp表述使用動態(tài)ip
address?是本機(jī)IP地址
netmask?子網(wǎng)掩碼
gateway?網(wǎng)關(guān)
如果使用nano編輯的話
ctrl+o? #保存配置
ctrl+x? #退出
設(shè)置DNS
linux系統(tǒng)的DNS信息是保存在/etc/resolv.conf , 但是在ubuntu中用vim打開這個文件你會發(fā)現(xiàn)有如下文字的提示
DO NOT EDIT THIS FILE BY HAND — YOUR CHANGES WILL BE OVERWRITTEN
所以不能直接個性這個文件,這個內(nèi)容可能會被覆蓋
在ubuntu中dns信息是放在/etc/resolvconf/resolv.conf.d/目錄下
一般情況下這個目錄下有base和head兩個文件夾
vim /etc/resolvconf/resolv.conf.d/base
nameserver?8.8.8.8
nameserver?114.114.114.114
保存后執(zhí)行
resolvconf -u
用以下命令使網(wǎng)絡(luò)設(shè)置生效
service networking restart
sudo /etc/init.d/networking restart
總結(jié)
以上是生活随笔為你收集整理的ubuntu设置网卡默认启动_ubuntu 网络配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 移动设计
- 下一篇: ubuntu18.04安装pycharm