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