1. Linux网络相关 ● ifconfig 查看网卡ip(yum install net-tools) ifconfig主要是可以手动启动、观察与修改网络接口的相关参数,可以修改的参数很多,包括IP参数以及MTU等都可以修改,它的语法如下:

[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.10  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::fc38:478e:adb0:ff3a  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b8:66:94  txqueuelen 1000  (Ethernet)
        RX packets 357026  bytes 66702829 (63.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 164637  bytes 64344797 (61.3 MiB)
        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 1  (Local Loopback)
        RX packets 68  bytes 5908 (5.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 68  bytes 5908 (5.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

● ifup ens33/ifdown ens33 实时地手动修改一些网络接口参数,可以利用ifconfig来实现,如果是要直接以配置文件,亦即是在 /etc/sysconfig/network-scripts里面的ifcfg-ethx等文件的设置参数来启动的话,那就得要通过ifdown或ifup来实现了。

[root@localhost ~]# ifdown ens33 && ifup ens33
成功断开设备 'ens33'。
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/2)

● 设定虚拟网卡ens33:0

[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33\:0
#设置虚拟网卡ens33:0  // ‘\’主要是为了脱义

● mii-tool ens33 查看网卡是否连接

[root@localhost network-scripts]# mii-tool ens33
ens33: negotiated 1000baseT-FD flow-control, link ok

● ethtool ens33 也可以查看网卡是否连接

● 更改主机名 hostnamectl set-hostname yunlinux

[root@localhost network-scripts]# hostname
localhost.localdomain
[root@localhost network-scripts]# hostnamectl set-hostname yunlinux
[root@localhost network-scripts]# hostname
yunlinux
[root@localhost network-scripts]# cat /etc/hostname
yunlinux

● DNS配置文件/etc/resolv.conf ● /etc/hosts文件 hosts文件主要是本机本地内部的域名解析,可以自行设置。


2. firewalld和netfilter ● selinux 临时关闭 setenforce 0

[root@localhost network-scripts]# setenforce 0

● selinux 永久关闭 vi /etc/selinux/config

注: 永久关闭需要重启系统

[root@localhost network-scripts]# getenforce
Permissive     #表示关闭状态
[root@localhost network-scripts]# setenforce 1     开启
[root@localhost network-scripts]# getenforce
Enforcing     #表示开启状态

firewalld简介 firewalld是centos7的一大特性,最大的好处有两个:支持动态更新,不用重启服务;第二个就是加入了防火墙的“zone”概念 什么是防火墙? 防火墙:(英文:Firewall),隔离工具 防火墙其实就是一个组件,这个组件能够屏蔽来自于互联网,或来自于企业内部的用户的攻击操作(DDos攻击,端口扫描等等);主要目的是防范非授权的访问的!它工作于网络或主机的边缘(通信报文的进出口),对于进出本网络或主机的报文根据事先定义的检查规则做匹配检测,对于能够被规则匹配到的报文做出相应处理,时刻检查出入防火墙的所有数据包,决定拦截或是放行哪些数据包。 它需要对我们主机上的或者是网络内的所有主机上的网络通信操作做一些防范性控制;根据这个防火墙到底是用于防护单台主机还是防护一个网络内的所有主机,通常分为网络防火墙和主机防火墙: 网络防火墙:工作与一个网络的边缘,能够实现对进出本网络的所有主机报文加以防护; 主机防火墙:主要是用来防范单台主机的进出报文;

● systemctl disable firewalled

[root@localhost network-scripts]# systemctl disable firewalld      禁用firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

● systemctl stop firewalld

[root@localhost network-scripts]# systemctl stop firewalld    停止

● yum install -y iptables-services

[root@localhost network-scripts]# yum install -y iptables-services     安装命令

● systemctl enable iptables

[root@localhost network-scripts]# systemctl enable iptables    使用
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.

● systemctl start iptables

[root@localhost network-scripts]# systemctl start iptables   启动

运行结果:


3. netfilter 5表5链介绍

● netfilter的5个表 ● filter表用于过滤包,最常用的表,有INPUT、FORWARD、OUTPUT三个链 ● nat表用于网络地址转换,有PREROUTING、OUTPUT、POSTROUTING三个链

其他扩展资料地址:http://blog.51cto.com/lizonglun/1770601


iptables/netfilter netfilter:在Linux内核中的一个软件框架,用于管理网络数据包。不仅具有网络地址转换(NAT)的功能,也具备数据包内容修改、以及数据包过滤等防火墙功能。利用运作于用户空间的应用软件,如iptable等,来控制Netfilter,系统管理者可以管理通过Linux操作系统的各种网络数据包

iptables:一个运行在用户空间的应用软件,通过控制Linux内核netfilter模块,来管理网络数据包的流动与转送。在大部分的Linux系统上面,iptables是使用/usr/sbin/iptables来操作,文件则放置在手册页Man底下,可以通过 man iptables(Centos 7中还需要使用man iptables-extensions ) 指令获取。通常iptables都需要内核层级的模块来配合运作,iptables是主要在内核层级里面iptables API运作功能的模块。因相关动作上的需要,iptables的操作需要用到超级用户的权限。

4. iptables语法 ● 查看iptables 规则:iptables -nvL service iptables restart //重启服务

[root@localhost network-scripts]# service iptables restart
Redirecting to /bin/systemctl restart iptables.service

cat /etc/sysconfig/iptables //配置文件 ● iptables -F 清空规则 ● service iptables save 保存规则 ● iptables -t nat //指定表 ● iptables -Z 可以把计数器清零 ● iptables -A INPUT -s 192.168.188.1 -p tcp --sport 1234 -d 192.168.1.3 --dport 80 -j DROP

[root@localhost network-scripts]# iptables -A INPUT -s 192.168.188.1 -p tcp --sport 1234 -d 192.168.1.3 --dport 80 -j DROP
#把数据包扔掉
[root@localhost network-scripts]# iptables -I INPUT -p tcp --dport 80 -j DROP

● iptables -I/-A/-D INPUT -s 1.1.1.1 -j DROP
-D 删除规则 ● iptables -I INPUT -s 192.168.1.0/24 -i eth0 -j ACCEPT ● iptables -nvL --line -numbers

#带编号显示规则
[root@localhost ~]# iptables -nvL --line-number

● iptables -D INPUT 1 //根据编号删规则 ● iptables -P INPUT DROP