10.11 Linux网络相关 10.12 firewalld和netfilter 10.13 netfilter5表5链介绍 10.14 iptables语法
Linux网络相关
ifocnfig 查看网卡ip(yum install net-tools)
ip add 查看网卡
ip add = ifocnfig
ifconfig 不显示down掉的网卡,只显示正在工作的网卡。
ifconfig -a 显示当前正在使用的网卡和down掉的网卡
ifdown enth0 关闭eth0网卡
ifup enth0 启动eth0网卡
当先执行ifdown eth0的时候就断开远程连接了,如果需要重新启动某个网卡,可以两天命令
一起执行 ifdown eth0 && ifup eth0
增加一个虚拟网卡eth0:0
也就是给虚拟网卡设置一个IP:
[root@centos7 ~]# cd /etc/sysconfig/network-scripts/
[root@centos7 network-scripts]# cp ifcfg-eth0 ifcfg-eth0:\0
ifcfg-eth0:\0 反斜杠表示脱义
修改网卡配置文件
vim ifcfg-eth0:0
修改内容如下:
修改NAME
NAME=eth0:0
修改IP地址
IPADDR=10.211.55.17
修改设备名
DEVICE=eth0:0
只留下子网掩码,网关,DNS1可以去掉
NETMASK=255.255.0.0
:wq保存即可
[root@localhost network-scripts]# ifdown eth0 && ifup eth0
成功断开设备 'eth0'。
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/151)
添加了一个新的IP地址:10.211.55.17
ifconfig 可以添加的新网卡eth0:0
eth0:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.211.55.17 netmask 255.255.0.0 broadcast 10.211.255.255
ether 00:1c:42:8c:25:09 txqueuelen 1000 (Ethernet)
同样也可以用虚拟网卡的IP地址登录ssh root@10.211.55.17
mii-tool enth0 查看网卡是否连接
如果显示not support
用ethtool eth0
[root@localhost network-scripts]# ethtool eth0
Settings for eth0:
Link detected: yes
更改主机名 hostnamectl set-hostname centos7
[root@localhost network-scripts]# hostnamectl set-hostname Centos7
[root@localhost network-scripts]# bash
[root@centos7 network-scripts]# cat /etc/hostname
centos7
[root@centos7 network-scripts]# exit
exit
DNS配置文件/etc/resolv.conf
[root@localhost network-scripts]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 119.29.29.29
DNS是在/etc/sysconfig/eth0下配置的,可以添加一个DNS2 google DNS
[root@localhost network-scripts]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DNS2:8.8.8.8
重新启动网卡
ifdown eth0 && ifup eth0
然后查看/etc/resolv.conf
[root@localhost network-scripts]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 119.29.29.29
nameserver 8.8.8.8
/etc/hosts 是windows、linux下都有的文件。 用来改自定义域名
cat /etc/hosts
当ping baidu.com 时候 是访问的百度的IP地址,但我也可以修改成ping 本机IP 10.211.55.17
vim /etc/hosts
添加
10.211.55.17 www.baidu.com
一行 一个IP地址可以有多个域名。
不同的IP地址对应相同的域名,以最后一个IP地址对应的域名为准。
firewalld和netfilter
防火墙1:selinux
selinux 临时关闭 setenforce 0
selinux 永久关闭 vi /etc/selinux/config
修改
SELINUX=disabled
查看selinux是否关闭:
getenforce
selinux 一般暂时关闭或者永久关闭也行。
防火墙2:netfilter
防火墙:netfilter ,filrewalld--->配置iptbales
centos7之前使用netfilter防火墙
关闭firewalld
systemctl disable firewalld(.service)
systemctl stop firewalld(.service)
开启netfilter 方法
(iptables是netfilter的一个工具)
yum install -y iptables-services
systemctl enable iptables
systemctl start iptables
防火墙:netfilter和firewalld 其底层都是iptables
就是配置iptables
netfilter5表5链介绍
netfilter的5个表(filter表,nat表,managle表,raw表,security表)
iptables手册:
更加参考手册man iptables 找到5个表(filter表,nat表,managle表,raw表,security表)
iptables传输数据包的过程
http://www.cnblogs.com/metoy/p/4320813.html
① 当一个数据包进入网卡时,它首先进入PREROUTING链,内核根据数据包目的IP判断是否需要转送出去。
② 如果数据包就是进入本机的,它就会沿着图向下移动,到达INPUT链。数据包到了INPUT链后,任何进程都会收到它。本机上运行的程序可以发送数据包,这些数据包会经过OUTPUT链,然后到达POSTROUTING链输出。
③ 如果数据包是要转发出去的,且内核允许转发,数据包就会如图所示向右移动,经过FORWARD链,然后到达POSTROUTING链输出。
filter表(内置的表)
用于过滤包,最常用的表,有INPUT、FORWARD、OUTPUT三个链
INPUT链(进来的数据链)
FORWARD链(判断目标地址是不是本机,或者对目标地址修改)
OUTPUT链(本机产生的包,出去之前所做的操作)
nat表(跟路由器 iptables nat表 端口重映射一样)
用于网络地址转换,有PREROUTING、OUTPUT、POSTROUTING三个链
PREROUTING 进来数据包所做的更改
OUTPUT出去数据包之前所做的更改
POSTROUTING出去数据包所做的更改
以下3个表几乎不常用:
managle表
用于给数据包做标记,几乎用不到
raw表
可以实现不同追踪某些数据包(从来不用)
security表
在centos6中并没有,用于强制访问控制
iptables语法
查看iptables规则
iptbales -nvL
规则存储在/etc/sysconfig/iptables
[root@localhost network-scripts]# cat /etc/sysconfig/iptables
iptables -F 清空规则
service iptables save 保存规则
service iptables restart 重启iptables 加载原来的配置文件里面的规则/etc/sysconfig/iptables
iptables -t nat //-t 指定表
iptables -t filter -nvL 查看filter里面的规则(不加-t 默认加载filter)
iptables -t nat -nvL 查看nat表里面的规则
iptables -Z 可以把计数器清零
添加一条规则:(-A)
(不加-t 默认filter表)
iptbales -A INPUT -s 192.168.188.1 -p tcp --sport 1234 -d 192.168.188.128 --dport 80 -j DROP
-A 意思是add 添加
-s source来源
-p 协议protocol tcp /udp
-d destination目标ip
-dport 目标端口
-j reject拒绝
DROP 丢掉 /REJECT 看一下不符合就丢掉数据
插入一条规则:(-I)
iptables -I INPUT -p tcp --dport 80 -j DROP
删除一条规则(-D)
iptbales -D INPUT -s 192.168.188.1 -p tcp --sport 1234 -d 192.168.188.128 --dport 80 -j DROP
iptables -D INPUT -p tcp --dport 80 -j DROP
但是我不记得具体的规则,可以这样删除规则,根据规则号删除规则:
iptables -nvL --line-numbers
iptables -D INPUT 1
-A 添加到规则最后面;-I (insert)把规则插入到前面;-D (delete )删除一条规则
-i 指定网卡inferace
iptables -I /-A/-D INPUT -s 192.168.1.0/24 -i eth0 -j ACCEPT
iptables -I INPUT -s 192.168.1.0/24 -i eth0 -j ACCEPT
对所有的规则设置策略policy,默认的策略是accept
DROP会拒绝所有的数据传入
iptables -P INPUT DROP
ACCEPT接收所有的数据包
iptables -P INPUT ACCEPT
10.11 Linux网络相关 10.12 firewalld和netfilter 10.13 netfilter5表5链介绍 10.14 iptables语法的更多相关文章
- Linux网络相关、firewalld和netfilter、netfilter5表5链介绍、iptables语法 使用介绍
第7周第3次课(5月9日) 课程内容: 10.11 Linux网络相关10.12 firewalld和netfilter10.13 netfilter5表5链介绍10.14 iptables语法 扩展 ...
- Linux centos7 Linux网络相关、firewalld和netfilter、netfilter5表5链介绍、iptables语法
一. Linux网络相关 yum install net-tools ifconfig查看网卡ip ifup ens33开启网卡 ifdown ens33关闭网卡 设定虚拟网卡ens33:0 mii- ...
- Linux网络相关命令firewalld和netfilter、iptables 使用(6/22)
iptables和netfilter的关系: netfilter在内核空间的代码根据table中的rules,完成对packet的分析和处置.但是这些table中的具体的防火墙rules,还是必须由系 ...
- Linux 网络相关命令 Cheat Sheet
以下漫画形式呈现的常用 Linux 网络相关命令速查表来自 twitter -
- Linux网络相关配置
一.修改网卡相关配置 Linux网络参数是在/etc/sysconfig/network-scripts/ifcfg-eth0中设置,其中ifcfg-eth0表示是第一个网卡,如果还有另外一块网卡,则 ...
- linux网络相关配置文件
linux系统一般来说分为两大类:1.RedHat系列:Redhat.Centos.Fedora等:2.Debian系列:Debian.Ubuntu等. linux系统中,TCP/IP网络是通过若干个 ...
- linux网络相关命令使用
A,iptables使用示例 1,将请求80端口的包发送给本机8180端口(这样,别的机器访问本机的80端口时会被转发到8180端口去) iptables -t nat -A PREROUTING - ...
- 10个linux网络和监控命令
我下面列出来的10个基础的每个linux用户都应该知道的网络和监控命令.网络和监控命令类似于这些: hostname, ping, ifconfig, iwconfig, netstat, nsloo ...
- Linux - 网络相关指令
系统时间与开关机 查看系统时间 date 查看硬件日期 hwclock 学习Linux不必全部指令都会,只要记住主要常用的几个就可以了.--MK 关机命令 shutdown init reboot p ...
随机推荐
- [EF] 如何在 Entity Framework 中以手动方式设定 Code First 的 Migration 作业
Entity Framework (简称 EF) 发展到现在, 版本已经进入 6.1.0, 距离我写的「在 VS2013 以 Code First 方式建立 EF 资料库」这篇文章已有半年的时间.如果 ...
- vue-router "path" is required in a route configuration
启用了动态路由,一直提示这个错误,页面打开也是空白,后来发现原来是component参数错误. 正确的写法为: component: () => import ('@/views/own-spa ...
- [转]Httrack工具与使用指南
HTTrack工具介绍 HTTrack是一个网站镜像工具,本来是用来抓取网站做离线浏览用的.但是HTTrack的爬虫特性和搜索引擎蜘蛛爬虫非常的像,这也逐渐应用到 SEO(搜索引擎优化)工作中.其实这 ...
- ubuntu 安装redis
1. 下载安装: cd /tmp wget http://redis.googlecode.com/files/redis-2.2.4.tar.gz tar -zxf redis-2.2.4.tar. ...
- mongo批量更新、导入导出脚本
批量更新,一定要加上最后的条件: db.getCollection('cuishou_user').update( {,,,,,]}}, //query {$set:{)}},// update {m ...
- AT24Cxx(EEPROM)子系统
1.配置内核 打开I2C功能: 打开杂项设备,该选项打开后,EEPROM也就打开了. 2. 修改代码 修改文件: linux/arch/arm/mach-s3c2440/mach-smdk2440.c ...
- Android——Service
xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= ...
- @Resource、@Autowired跟default-autowire区别联系
@Resource.@Autowired和default-autowire区别联系 今天看了一工程,里面既有default-autowire,又有@Autowired,还有@Resource.我就不明 ...
- webpack7--css压缩成单独的css文件
先看下下面的图片: 我们可以看到,通过Webpack打包后,默认CSS是通过 内部样式表 写入的.我们如何把压缩后的CSS单独导出为CSS 呢? 1.安装 extract-text-webpack-p ...
- (笔记)Linux Root下的.gvfs出现异常解决办法
在linux系统下安装软件或复制文件的时候,复制不成功,出现错误如下: error: failed to stat /home/dade/.gvfs: Permission denied. 表面上看: ...