天天看點

72.liunx網絡相關和防火牆ifconfig指令liunx防火牆netfilteriptables

ifconfig指令被用于配置和顯示Linux核心中網絡接口的網絡參數。用ifconfig指令配置的網卡資訊,在網卡重新開機後機器重新開機後,配置就不存在。要想将上述的配置資訊永遠的存的電腦裡,那就要修改網卡的配置檔案了。

ifconfig 【參數】

up 啟動指定網絡裝置/網卡

down 關閉指定網絡裝置/網卡

-arp 設定指定網卡是否支援ARP協定

-promisc 設定是否支援網卡的promiscuous模式,如果選擇此參數,網卡将接收網絡中發給它所有的資料包

-allmulti 設定是否支援多點傳播模式,如果選擇此參數,網卡将接收網絡中所有的多點傳播資料包

-a 顯示全部接口資訊

-s 顯示摘要資訊(類似于 netstat -i)

add 給指定網卡配置IPv6位址

del 删除指定網卡的IPv6位址

<硬體位址> 配置網卡最大的傳輸單元

mtu<位元組數> 設定網卡的最大傳輸單元 (bytes)

netmask<子網路遮罩> 設定網卡的子網路遮罩

tunel 建立隧道

dstaddr 設定一個遠端位址,建立點對點通信

-broadcast<位址> 為指定網卡設定廣播協定

-pointtopoint<位址> 為網卡設定點對點通訊協定

multicast 為網卡設定多點傳播标志

為網卡設定IPv4位址

txqueuelen<長度> 為網卡設定傳輸列隊的長度

檢視網卡資訊

[root@localhost /]# ifconfig

eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 192.168.0.168 netmask 255.255.255.0 broadcast 192.168.0.255

inet6 fe80::20c:29ff:fe1f:2eab prefixlen 64 scopeid 0x20<link>

ether 00:0c:29:1f:2e:ab txqueuelen 1000 (Ethernet)

RX packets 2630 bytes 246226 (240.4 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 1543 bytes 178989 (174.7 KiB)

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 0 (Local Loopback)

RX packets 0 bytes 0 (0.0 B)

TX packets 0 bytes 0 (0.0 B)

cenots7之前是使用netfilter cenots7後 是使用 firewalld

[root@localhost ~]# systemctl stop firewalld //關閉firewalld服務

[root@localhost ~]# systemctl disable firewalld //禁止firewalld服務開機啟動

Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

[root@localhost ~]# yum install -y iptables-services //安裝iptables-services,以便使用iptables

[root@localhost ~]# systemctl enable iptables //開機啟動iptables

Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.

[root@localhost ~]#systemctl start iptables //啟動iptables

iptables指令是Linux上常用的防火牆軟體,是netfilter項目的一部分。可以直接配置,也可以通過許多前端和圖形界面配置。

iptables [選項]【參數】

-t<表>:指定要操縱的表;

-A:向規則鍊中添加條目;

-D:從規則鍊中删除條目;

-i:向規則鍊中插入條目;

-R:替換規則鍊中的條目;

-L:顯示規則鍊中已有的條目;

-F:清楚規則鍊中已有的條目;

-Z:清空規則鍊中的資料包電腦和位元組計數器;

-N:建立新的使用者自定義規則鍊;

-P:定義規則鍊中的預設目标;

-h:顯示幫助資訊;

-p:指定要比對的資料包協定類型;

-s:指定要比對的資料包源ip位址;

-j<目标>:指定要跳轉的目标;

-i<網絡接口>:指定資料包進入本機的網絡接口;

-o<網絡接口>:指定資料包要離開本機所使用的網絡接口。

iptables -t 表名 <-A/I/D/R> 規則鍊名 [規則号] <-i/o 網卡名> -p 協定名 <-s 源IP/源子網> --sport 源端口 <-d 目标IP/目标子網> --dport 目标端口 -j 動作

raw:進階功能,如:網址過濾。

mangle:資料包修改(QOS),用于實作服務品質。

net:位址轉換,用于網關路由器。

filter:包過濾,用于防火牆規則。

INPUT鍊:處理輸入資料包。

OUTPUT鍊:處理輸出資料包。

PORWARD鍊:處理轉發資料包。

PREROUTING鍊:用于目标位址轉換(DNAT)。

POSTOUTING鍊:用于源位址轉換(SNAT)。

accept:接收資料包。

DROP:丢棄資料包。

REDIRECT:重定向、映射、透明代理。

SNAT:源位址轉換。

DNAT:目标位址轉換。

MASQUERADE:IP僞裝(NAT),用于ADSL。

LOG:日志記錄。

清除已有iptables規則

iptables -F

iptables -X

iptables -Z

檢視已添加的iptables規則

iptables -NVL

将所有iptables以序号标記顯示,執行:

iptables -L -n --line-numbers

比如要删除INPUT裡序号為8的規則,執行:

iptables -D INPUT 8

本文轉自 閃電王 51CTO部落格,原文連結:http://blog.51cto.com/sdwaqw/2068774

繼續閱讀