树莓派 网络配置 eth0 wlan0 静态ip配置 防火墙

Eth0 静态ip配置:

  关于静态ip的配置,在/etc/network/interfaces文件中已有说明,如下:

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

说明要配置静态ip 需要到/etc/dhcpcd.conf中设置,interfaces里面不用动,在dhcpcd.conf加入代码如下:


interface eth0
static ip_address=192.168.1.240/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

interface wlan0
static ip_addresss=192.168.1.241/24
static routers=192.168.1.1
static domain_name_serverss=192.168.1.1

至此,eth0的ip地址开机自动设置为240,但是wlan0的ip地址并不起作用

 

Wlan0 网络配置: 在文件 /etc/network/interfaces 中直接配置如下:

auto lo
iface lo inet loopback

iface eth0 inet manual

auto wlan0
allow-hotplug wlan0
#iface wlan0 inet manual
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface wlan0 inet static
wpa-ssid "ssid"
wpa-psk "pswd"
address 192.168.1.241
netmask 255.255.255.0
gateway 192.168.1.1
network 192.168.1.1
iface default inet dhcp

 

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

 

至此,wlan正常启动,ip固定在241上。

 

防火墙设置:

设置防火墙规则,新建一个文件,设置规则如下:

/sbin/iptables -P INPUT ACCEPT  
/sbin/iptables -F  DELETE ALL RULES IN A CHAIN OR ALL CHAIN删除所有的规则 
/sbin/iptables -X  DELETE A USER DEFINED CHAIN
/sbin/iptables -Z  ZERO COUNTERS IN CHAIN OR ALL CHAINS

/sbin/iptables -A INPUT -i lo -j ACCEPT   回环允许
/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT  ssh允许
/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT  http允许
/sbin/iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT  ping允许
/sbin/iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT  所有已建立的链接允许,即对外允许
/sbin/iptables -P INPUT DROP   其他丢弃


/sbin/iptables-save > /etc/iptables.up.rules  保存防火墙配置到 /etc/iptables.up.rules文件中

 

在/etc/network/interfaces 中,在eth0连接上之后加载防火墙规则

iface eth0 inet manual

pre-up iptables-restore < /etc/iptables.up.rules

posted on 2017-09-06 14:06  Spencer_Rasp  阅读(7430)  评论(0编辑  收藏  举报

导航