2018.5.8 七周三次課(firewalld和netfilter,iptables語法)
阿新 • • 發佈:2018-05-09
Linux網絡相關 firewalld和netfilter 防火墻 netfilter5表5鏈介紹 iptables語法 Linux網絡相關
centOS版本6裏,如果想用ifconfig 得安裝個net-tools
[root@localhost ~]# yum install -y net-tools
關閉一個網卡
[root@localhost ~]# ifdown ens33
開啟網卡
[root@localhost ~]# ifup ens33
重啟網卡
[root@localhost ~]# ifdown ens33 && ifup ens33
添加一個虛擬網卡
[root@localhost ~]# cd /etc/sysconfig/network-scripts/ [root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33\:0 #進入到配置文件,拷貝一份IP目錄,然後修改名為ens33:0,這裏的“\”是為了脫義冒號
修改虛擬網卡的配置文件
[root@localhost network-scripts]# vi ifcfg-ens33:0
這裏就編輯三個地方就可以,NAME和DEVICE還有IP地址
然後重啟網卡:
[root@localhost network-scripts]# ifdown ens33 && ifup ens33
添加成功。
查看一個網卡有沒有插著網線
[root@localhost network-scripts]# mii-tool ens33 #後面跟網卡的名字 ens33: negotiated 1000baseT-FD flow-control, link ok #看看後面是不是ok
修改主機名 hostnamectl set-hostname zhang-01
[root@localhost ~]# hostnamectl set-hostname zhang-01
[root@localhost ~]# bash #打開一個子shell看下是否修改成功
[root@zhang-01 ~]#
DNS配置文件在 /etc/resolv.conf
[root@zhang-01 ~]# cat /etc/resolv.conf # Generated by NetworkManager nameserver 119.29.29.29 nameserver 114.114.114.114
firewalld和netfilter(防火墻)
Linux防火墻-netfilter:
selinux臨時關閉 setenforce 0
selinux永久關閉 vi /etc/selinux/config
centos7之前使用netfilter防火墻
centos7開始使用firewalld防火墻
關閉firewalld開啟netfilter方法
systemctl stop firewalld 服務關掉
systemctl disable firewalled 關閉firewalled 不讓開機啟動
yum install -y iptables-services 如果再開啟firewalled需要安裝一個包
systemctl enable iptables
systemctl start iptables 開啟
永久關閉防火墻,編輯配置文件 SELINUX=enforcing修改成disabled
[root@zhang-01 ~]# vi /etc/selinux/config
查看iptables服務
[root@zhang-01 ~]# iptables -nvL #可以查看裏面默認的規則 5表5列
Linux防火墻-netfilter
netfilter的5個表
filter表用於過濾包,最常用的表,有INPUT、FORWARD、OUTPUT三個鏈
nat表用於網絡地址轉換,有PREROUTING、OUTPUT、POSTROUTING三個鏈
managle表用於給數據包做標記,幾乎用不到
raw表可以實現不追蹤某些數據包,阿銘從來不用
2018.5.8 七周三次課(firewalld和netfilter,iptables語法)