2018-03-21 Linux學習
阿新 • • 發佈:2018-03-21
Linux 學習 2018-03-21 10.11 Linux 網絡相關
ifconfig //查看網卡ip yum install net-tools ifup ens33 / ifdown ens33 設定虛擬網卡 ens33:0 mii-tool ens33 //查看網卡是否連接 ethtool ens33 //也可以查看網卡是否連接 更改主機名 hostnamectl set-hostname aminglinux DNS配置文件 /etc/resolv.conf /etc/hosts 文件 ifdown ens33 && ifup ens33 ifdown ens33; ifup ens33 設定虛擬網卡 ens33:0 復制 ifcfg-ens33 為 ifcfg-ens33\:0 修改 NAME=ens33:0 刪除 DNS 和 GATEWAY 重啟網卡,測試網卡ping [root@aming-01 network-scripts]# cat /etc/hostname aming-01 [root@aming-01 network-scripts]# cat /etc/resolv.conf # Generated by NetworkManager nameserver 119.29.29.29 [root@aming-01 network-scripts]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 hosts 格式 192.168.133.150 www.qq160.com www.aminglinux.com www.zzz.com
10.12 firewalld 和 netfilter
selinux 臨時關閉 setenforce 0 selinux 永久關閉 vi /etc/selinux/config SELINUX=Permissive centos7 之前使用 netfilter 防火墻 centos7 開始使用 firewalld 防火墻 關閉 firewalld 開啟 netfilter 方法 systemctl stop firewalld systemctl disable firewalld yum install -y iptables-services systemctl enable iptables systemctl start iptables [root@aming-01 ~]# systemctl disable firewalld [root@aming-01 ~]# systemctl stop firewalld [root@aming-01 ~]# yum install -y iptables-services [root@aming-01 ~]# systemctl enable iptables [root@aming-01 ~]# systemctl start iptables.service [root@aming-01 ~]# iptables -nvL //查看防火墻默認開啟的機制
10.13 netfilter 5表5鏈介紹
filter: This is the default table (if no -t option is passed). It contains the built-in chains INPUT (for packets destined to local sockets), FORWARD (for packets being routed through the box), and OUTPUT (for locally-generated packets). nat: This table is consulted when a packet that creates a newconnection is encountered. It consists of three built-ins:PREROUTING (for altering packets as soon as they come in),OUTPUT (for altering locally-generated packets before rout‐ing), and POSTROUTING (for altering packets as they are about to go out). IPv6 NAT support is available since ker‐nel 3.7. netfilter 的 5個表 filter表示於過濾包,最常用的表,有 INPUT、FORWARD、OUTPUT 三個鏈 nat表用於網絡地址轉換,有 PREROUTING、OUTPUT、POSTROUTING 三個鏈 managle 表用於給數據包做標記,幾乎用不到 raw 表可以實現不追蹤某些數據包,阿銘從來不用 security 表在centos6中並沒有,用於強制訪問控制(MAC)的網絡規則,阿銘沒用過 參考文章 http://www.cnblogs.com/metoy/p/4320813.html
10.14 iptables 語法
Linux 防火墻 netfilter
數據包流向與 netfilter 的5個鏈
PREROUTING:數據包進入路由表之前
INPUT:通過路由表後目的地為本機
FORWARD:通過路由表後,目的地不為本機
OUTPUT:由本機產生,向外發出
POSTROUTING:發送到網卡接口之前
cat /etc/sysconfig/iptables
[root@aming-01 ~]# cat /etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
查看 iptables 規則:iptables -nvL
iptables -F 清空規則
service iptables save 保存規則
iptables -t nat //-t 制定表
iptables -Z 可以把計數器清零
iptables -A INPUT -s 192.168.188.1 -p tcp --sport 1234 -d 192.168.188.128 --dport 80 -j DROP
iptables -I/-A/-D INPUT -s 1.1.1.1 -j DROP
iptables -I INPUT -s 192.168.1.0/24 -i eth0 -j ACCEPT
iptables -nvL --line-numbers
iptables -D INPUT 1
iptables -P INPUT DROP
-A 增加,在最後
-I 插入,到前面
-D 刪除
-P 默認的規則
-F 清空
-Z 計數器清零
-s 來源
-p 協議
-d 目標
-i 網卡名稱
--sport 來源端口
--dport 目標端口
2018-03-21 Linux學習