Raspberry pi 設定 固定 IP

本版討論Raspberry PI相關技術開發、設計與應用
回覆文章
inho
文章: 27
註冊時間: 2017-12-08, 23:00

Raspberry pi 設定 固定 IP

文章 inho » 2018-02-08, 20:07

* Setting a static IP
1.有線 DHCP 設定
2 無線 DHCP 設定
3.有線固定IP設定
4.無線固定IP設定

主要設定檔案: /etc/network/interfaces
參考網站:
https://sites.google.com/site/raspberyp ... ian-dedhcp
https://icodding.blogspot.tw/2016/02/raspberry-pi.html
***************************************************
一、先取得 RPi 開機後的網路連線狀況:
滑鼠移至右上方網路狀態 Icon時,會顯示有線及無線網路狀態訊息:
wlan0 : Associated with XXXXX (如果是中華電信網路,XXXXX 就是 CHTXXXX,),如果已經連上網路,會再出現:
wlan0 : Configuared 192.168.X.X / 24
eth0 : Link is down
***********************************************************8
從Terminal視窗,輸入ifconfig指令:
$ ifconfig
會顯示關於eth0、lo、及 wlan0的相關資訊
enxb827ebeb9896: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether b8:27:eb:eb:98:96 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 54 bytes 3364 (3.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 54 bytes 3364 (3.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.104 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::eb8f:dea3:471e:bff prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:be:cd:c3 txqueuelen 1000 (Ethernet)
RX packets 269126 bytes 180037165 (171.6 MiB)
RX errors 0 dropped 1 overruns 0 frame 0
TX packets 279503 bytes 267859526 (255.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
********************************************************************************
編輯 /etc/dhcpcd.conf file :
$ sudo vi /etc/dhcpcd.conf
會看到
# Example static IP configuration
# interface eth0
# static ip_address=192.168.1.15/24
# static routers=192.168.1.1
# static domain_name_servers=192.168.1.1
將上列資料改成:
interface eth0
static ip_address=192.168.1.15/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
及設定固定IP 為:192.168.1.15
**************************************************************************************
設定 Hinet Static IP 請參考:http://blog.itist.tw/2015/02/raspberry- ... ction.html
直接從官方套件庫安裝 PPPoE 撥接程式。
$ sudo apt-get -y install pppoeconf
並設定撥接參數:
$ sudo pppoeconf
然後,啟動撥接連線「pon」指令。
$ sudo pon dsl-provider
若要斷線:
$ sudo poff
*****************************************************************************************8
設定 固定 IP:
編輯 /etc/network/interfaces 檔案:
$ sudo vi /etc/network/interfaces

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

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet static
address 1XX.A.B.XX
netmask 255.255.255.0
network 1XX.A.B.0
broadcast 1XX.A.B.255
gateway 1XX.A.B.254

allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

回覆文章