1. 程式人生 > >Linux防火墻基礎

Linux防火墻基礎

雲計算基礎 linux基礎


SElinux配置


[root@server0 ~]# getenforce

Enforcing

[root@server0 ~]# setenforce 0

[root@server0 ~]# getenforce

Permissive

[root@server0 ~]# setenforce 1

[root@server0 ~]# getenforce

Enforcing



######################################################################################


配置聚合鏈路

[root@server0 ~]# man teamd.conf /example 查找相關命令


1.添加聚合連接team0 #加隊取名定模式


[root@server0 ~]# nmcli connection add type team con-name team0 ifname team0 config ‘{ "runner": {"name": "activebackup"}}‘

Connection ‘team0‘ (3d3cdab0-e8aa-4db0-90de-7863c6d9f798) successfully added.



[root@server0 ~]# cat /etc/sysconfig/network-scripts/ifcfg-team0

DEVICE=team0

TEAM_CONFIG="{ \"runner\": {\"name\": \"activebackup\"}}"

DEVICETYPE=Team

BOOTPROTO=dhcp

DEFROUTE=yes

PEERDNS=yes

PEERROUTES=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_PEERDNS=yes

IPV6_PEERROUTES=yes

IPV6_FAILURE_FATAL=no

NAME=team0

UUID=3d3cdab0-e8aa-4db0-90de-7863c6d9f798

ONBOOT=yes


[root@server0 ~]# ifconfig

team0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500

ether 6a:1f:d4:35:9f:2b txqueuelen 0 (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


2.team0中添加網卡 #slave 奴隸 添加奴隸 選卡


[root@server0 ~]# nmcli connection add type team-slave ifname eth1 master team0

Connection ‘team-slave-eth1‘ (e0deb3ce-ed1b-4001-9616-bf483e3240f7) successfully added.

[root@server0 ~]# nmcli connection add type team-slave ifname eth2 master team0

Connection ‘team-slave-eth2‘ (275238d8-df7a-4761-8635-0815a6510b6f) successfully added.


3.配置team0的IP地址

[root@server0 ~]# nmcli connection modify team0 ipv4.method manual ipv4.addresses 192.168.1.1/24 connection.autoconnect yes


4.激活team0和各個網卡

[root@server0 ~]# nmcli connection up team-slave-eth1

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)

[root@server0 ~]# nmcli connection up team-slave-eth2

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)

[root@server0 ~]# nmcli connection up team0

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)


5.驗證

[root@server0 ~]# teamdctl team0 state

setup:

runner: activebackup

ports:

eth2

link watches:

link summary: up

instance[link_watch_0]:

name: ethtool

link: up

eth1

link watches:

link summary: up

instance[link_watch_0]:

name: ethtool

link: up

runner:

active port: eth2


刪除相關設置

nmcli connection delete team-slave-eth1

nmcli connection delete team-slave-eth2

nmcli connection delete team0


####################################################################################


自定義命令


[root@server0 ~]# vim /root/.bashrc #影響root文件

alias hello=‘echo hello‘

[root@server0 ~]# vim /home/student/.bashrc #影響student文件

alias hi=‘echo hi‘

[root@server0 ~]# vim /etc/bashrc #影響全局配置

alias xixi=‘echo xixi‘


退出遠程連接重新登陸

[root@server0 ~]# exit

登出

[root@room8pc205 桌面]# s

Last login: Wed Nov 1 08:33:41 2017 from 172.25.0.250


驗證

[root@server0 ~]# hello

hello

[root@server0 ~]# xixi

xixi

[root@server0 ~]# hi

bash: hi: 未找到命令...


換到用戶student驗證

[student@server0 root]$ hi

hi

[student@server0 root]$ xixi

xixi

[student@server0 root]$ hello

bash: hello: 未找到命令...

[student@server0 root]$


#######################################################################################


防火墻策略管理


搭建基本的web服務

服務端 Apache httpd


1 安裝httpd軟件

yum -y install httpd


2 重啟httpd服務 設置開機自啟

[root@server0 ~]# systemctl restart httpd

[root@server0 ~]# systemctl enable httpd


3 設計簡單網頁

[root@server0 ~]# vim /var/www/html/index.html


<marquee><font color=green><h1>hahahahahahahahaha


[root@server0 ~]# firefox 172.25.0.11



4 FTP服務的搭建 #FTP做文件傳輸服務

[root@server0 ~]# yum -y install vsftpd

[root@server0 ~]# systemctl restart vsftpd

[root@server0 ~]# systemctl enable vsftpd



5 測試

[root@server0 ~]# firefox ftp://172.25.0.11


防火墻


查看防火墻狀態

[root@server0 ~]# systemctl status firewalld.service

firewalld.service - firewalld - dynamic firewall daemon

Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled)

Active: active (running) since 三 2017-11-01 08:28:25 CST; 7h ago

Main PID: 481 (firewalld)

CGroup: /system.slice/firewalld.service

└─481 /usr/bin/python -Es /usr/sbin/firewalld --nofork --...


11月 01 08:28:25 localhost systemd[1]: Started firewalld - dynamic....

Hint: Some lines were ellipsized, use -l to show in full.



預設安全區域

public

trusted

block

drop


##################################################################################


防火墻判斷的規則:匹配及停止


1.首先看請求(客戶端)當中的源IP地址,所有區域中是否有對於改IP地址的策略,如果有則該請求進入該區域

2.進入默認區域



虛擬機desktop0:

# firefox http://172.25.0.11 #訪問失敗

# firefox ftp://172.25.0.11 #訪問失敗

虛擬機server0:

# firewall-cmd --get-default-zone #查看默認區域

# firewall-cmd --zone=public --list-all

# firewall-cmd --zone=public --add-service=http #添加服務

# firewall-cmd --zone=public --list-all #查看區域規則信息

虛擬機desktop0:

# firefox http://172.25.0.11 #訪問成功

# firefox ftp://172.25.0.11 #訪問失敗

虛擬機server0:

# firewall-cmd --zone=public --add-service=ftp

# firewall-cmd --zone=public --list-all

虛擬機desktop0:

# firefox ftp://172.25.0.11 #訪問成功


#####################################################

--permanent選項:實現永久設置


虛擬機server0:


# firewall-cmd --reload #重新加載防火墻

# firewall-cmd --zone=public --list-all


# firewall-cmd --permanent --zone=public --add-service=ftp

# firewall-cmd --permanent --zone=public --add-service=http


# firewall-cmd --reload #重新加載防火墻

# firewall-cmd --zone=public --list-all


####################################################

修改默認的區域,不需要加上--permanent


虛擬機desktop0:

# ping 172.25.0.11 #可以通信

虛擬機server0:

# firewall-cmd --set-default-zone=block #修改默認區域

# firewall-cmd --get-default-zone #查看默認區域


虛擬機desktop0:

# ping 172.25.0.11 #不可以通信


虛擬機server0:

# firewall-cmd --set-default-zone=drop

# firewall-cmd --get-default-zone

虛擬機desktop0:

# ping 172.25.0.11 #通信無反饋


######################################################


虛擬機server0:

# firewall-cmd --permanent --zone=public --add-source=172.25.0.10


# firewall-cmd --zone=public --list-all

# firewall-cmd --reload

# firewall-cmd --zone=public --list-all


虛擬機desktop0:

# firefox http://172.25.0.11


##################################################


實現本機的端口映射

本地應用的端口重定向(端口1 --> 端口2)

– 從客戶機訪問 端口1 的請求,自動映射到本機 端口2

– 比如,訪問以下兩個地址可以看到相同的頁面:


虛擬機desktop0:

# firefox http://172.25.0.11:5423-------》172.25.0.11:80


虛擬機server0:

# firewall-cmd --permanent --zone=public

--add-forward-port=port=5423:proto=tcp:toport=80


# firewall-cmd --reload


# firewall-cmd --zone=public --list-all



虛擬機desktop0:

# firefox http://172.25.0.11:5423





Linux防火墻基礎