歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Ubuntu Linux >> Ubuntu13.04設置靜態ip(無論筆記本、台式、虛擬機)

Ubuntu13.04設置靜態ip(無論筆記本、台式、虛擬機)

日期:2017/3/3 17:01:56   编辑:Ubuntu Linux

# 操作系統:Ubuntu13.04

#

# Author: 晴天

#文章地址:http://blog.csdn.net/sunnypotter/article/details/22598201

# 設置靜態IP:

#

# 准備:

# 1、查看在用的網卡、IP及子網掩碼netmask, 我的是eth0

ifconfig

eth0 Link encap:Ethernet HWaddr ec:9a:74:36:c8:8c

inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0

# IP:192.168.1.100, netmask:255.255.255.0

# 2、查看網關gateway

route -n

Destination Gateway Genmask Flags Metric Ref Use Iface

0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0

# gateway: 192.168.1.1

# dns: 192.168.1.1 # 一般都和gateway,當然也可設置其他dns

# 3、現在開始設置靜態ip

sudo vim /etc/network/interfaces

*********

# interfaces(5) file used by ifup(8) and ifdown(8)

auto lo

iface lo inet loopback

# Set Static IP

auto eth0 # 我的網卡

iface eth0 inet static # 靜態,與之相對的是動態(dhcp,即iface eth0 inet dhcp)

address 192.168.1.100 # 你可以設置同網段的可用ip, 如192.168.1.102

gateway 192.168.1.1 # 網關

netmask 255.255.255.0 # 子網掩碼

dns-nameservers 192.168.1.1 # 可設置多個dns, 也可不在這裡設置,編輯/etc/resolv.conf
dns-nameservers 114.114.114.114

# 4、重啟網卡

sudo service networking restart

# 或 sudo /etc/init.d/networking restart

# 還是不行的話,請重啟reboot

# 注意:

#當沒有設置dns-nameservers 時,需要在/etc/resolv.conf手動添加

sudo vim /etc/resolv.cof

nameserver 192.168.1.1

# 另外:

在相對較早的版本中,你需要設置/etc下的resolv.conf文件,並添加nameserver,這樣才可以連接互聯網,否則只能通過ip訪問,無法解析網址.(nslookup 可查看網址ip, 當然,你必須先有dns).

在Ubuntu12.04之後,已經不再推薦這種方式,因為無論你想在該配置文件中設置什麼值,重新啟動後都會被還原為初始狀態。(當然不包括開機啟動腳本自動設置)

推薦的做法是,直接在interfaces配置文件中加入dns-nameservers <網關ip>這一行.

Copyright © Linux教程網 All Rights Reserved