Configuring a Static IP address on your Raspberry Pi

原文地址:http://elinux.org/Configuring_a_Static_IP_address_on_your_Raspberry_Pi

Configure eth0 to not use DHCP

By default the Raspberry Pi uses DHCP to configure its network interfaces, including, on the model B, the built-in ethernet port. If you want to change this so the ethernet port has a static IP address, here's how.

DHCP for eth0 is enabled in the file /etc/network/interfaces. Here is what it looks like by default on a Raspberry Pi under the official version of Raspbian:

auto lo

iface lo inet loopback
iface eth0 inet dhcp

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

(Note: there is no actual wlan0 interface unless you attach a wireless USB network adapter. The entries that refer to wlan0 are there for when you do ;-) ).

Instead of the line:

iface eth0 inet dhcp

you need lines like this:

iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0
gateway 192.168.1.254

The above example assigns the address 192.168.1.1 to eth0 with a subnet mask of 255.255.255.0, and sets the default gateway to 192.168.1.254.

Edit the file /etc/network/interfaces with the nano utility like this:

sudo nano /etc/network/interfaces

The second thing you need to do is check that you have a valid DNS server listed in /etc/resolv.conf. Edit this file using nano and add your DNS server if it is not already there. If you are using a broadband router, add the address of your router as the DNS server.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值