linux網(wǎng)絡(luò)相關(guān)
ifdown ens33 關(guān)閉網(wǎng)卡&& ifup ens33 啟動網(wǎng)卡 (&&一起執(zhí)行)
應(yīng)用場景:當(dāng)想單獨更改某個網(wǎng)卡的信息時,可使用此命令
設(shè)定虛擬網(wǎng)卡
cd /etc/sysconfig/network-scripts/ 進(jìn)入網(wǎng)卡目錄
cp ifcfg-ens33 ifcfg-ens33:0 拷貝網(wǎng)卡配置文件
vi !$編輯配文件
修改name :ens33:0
device :ens33 :0
ipaddr 更換ip
刪除dns1 gateway
修改后關(guān)閉,開啟網(wǎng)卡。
查看網(wǎng)卡是否連接(link ok表示連接)
[root@g_linux01 network-scripts]# mii-tool ens33 ens33: negotiated 1000baset-fd flow-control, link ok
如果mii-tool ens33不支持 也可用ethtool ens33
[root@g_linux01 network-scripts]# ethtool ens33 settings for ens33: supported ports: [ tp ] supported link modes: 10baset/half 10baset/full 100baset/half 100baset/full 1000baset/full supported pause frame use: no supports auto-negotiation: yes advertised link modes: 10baset/half 10baset/full 100baset/half 100baset/full 1000baset/full advertised pause frame use: no advertised auto-negotiation: yes speed: 1000mb/s duplex: full port: twisted pair phyad: 0 transceiver: internal auto-negotiation: on mdi-x: off (auto) supports wake-on: d wake-on: d current message level: 0x00000007 (7) drv probe link link detected: yes 更改主機(jī)名
hostnamectl set-hostname [主機(jī)名] (centos7的命令)
配置文件在/etc/hostname
dns配置文件
/etc/resolv.conf(可臨時更改,想永久更改要在網(wǎng)卡配置文件中改)
etc/hosts 更改本機(jī)域名解析
以先出現(xiàn)的記錄為主。 這個文件也是從上到下依次執(zhí)行的,127.0.0.1是特例,本機(jī)ip優(yōu)先級高
firewalld和netfilter
復(fù)習(xí)selinux
修改配置文件中selinux=disabled
getenforce 可查詢selinux是否開啟
可能返回結(jié)果有三種:enforcing、permissive和disabled。disabled 代表 selinux 被禁用,permissive 代表僅記錄安全警告但不阻止可疑行為,enforcing 代表記錄警告且阻止可疑行為。
firewalld
centos7 默認(rèn)開啟firewalld 關(guān)閉netfilter,netfilter 是centos6的防火墻。但7依然可以用
關(guān)閉firewalld 流程
systemctl disable firewalld 不開機(jī)啟動 systemctl stop firewalld 在關(guān)掉
開啟netfilter
先安裝yum install -y iptables-services systemctl enable iptables 設(shè)為開機(jī)啟動 systemctl start iptables 啟動服務(wù) netfilter5個表5個鏈介紹
filter,nat,mangle,raw,默認(rèn)表是filter(沒有指定表的時候就是filter表)。
filter:一般的過濾功能
nat:用于nat功能(端口映射,地址映射等)
mangle:用于對特定數(shù)據(jù)包的修改
raw:優(yōu)先級最高,設(shè)置raw時一般是為了不再讓iptables做數(shù)據(jù)包的鏈接跟蹤處理,提高性能
數(shù)據(jù)報從進(jìn)入系統(tǒng),進(jìn)行ip校驗以后,首先經(jīng)過第一個hook函數(shù)nf_ip_pre_routing進(jìn)行處理; 然后就進(jìn)入路由代碼,其決定該數(shù)據(jù)報是需要轉(zhuǎn)發(fā)還是發(fā)給本機(jī)的; 若該數(shù)據(jù)報是發(fā)被本機(jī)的,則該數(shù)據(jù)經(jīng)過hook函數(shù)nf_ip_local_in處理以后然后傳遞給上層協(xié)議; 若該數(shù)據(jù)報應(yīng)該被轉(zhuǎn)發(fā)則它被nf_ip_forward處理; 經(jīng)過轉(zhuǎn)發(fā)的數(shù)據(jù)報經(jīng)過最后一個hook函數(shù)nf_ip_post_routing處理以后,再傳輸?shù)骄W(wǎng)絡(luò)上。 本地產(chǎn)生的數(shù)據(jù)經(jīng)過hook函數(shù)nf_ip_local_out 處理后,進(jìn)行路由選擇處理,然后經(jīng)過nf_ip_post_routing處理后發(fā)送出去。 iptables語法
案例:http://blog.chinaunix.net/uid-9950859-id-98279.html
查看默認(rèn)規(guī)則
[root@g_linux01 ~]# iptables -nvl chain input (policy accept 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 116k 28m accept all — * * 0.0.0.0/0 0.0.0.0/0 ctstate related,established 0 0 accept all — lo * 0.0.0.0/0 0.0.0.0/0 11342 963k input_direct all — * * 0.0.0.0/0 0.0.0.0/0 11342 963k input_zones_source all — * * 0.0.0.0/0 0.0.0.0/0 11342 963k input_zones all — * * 0.0.0.0/0 0.0.0.0/0 0 0 drop all — * * 0.0.0.0/0 0.0.0.0/0 ctstate invalid 11330 963k reject all — * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
重啟規(guī)則service iptabales restart(重啟后會加載配置文件中的規(guī)則)
保存規(guī)則service iptables save(修改后不保存,重啟后會失效)
規(guī)則保存在 cat /etc/sysconfig/iptables(如果沒有安裝yum install iptables-services)
iptables -f 清空規(guī)則
iptables -t filter -nvl (指定顯示哪個表的規(guī)則,不加-t 默認(rèn)顯示filter)
iptables -t nat -nvl
iptables -z 清空計數(shù)器
限制某ip登錄
iptables -a input -s 192.168.188.1 -p tcp –sport 1234 -d 192.168.188.128 –dport 80 -j dorp/reject
-a 增加一條規(guī)則,針對input鏈(在最后插入規(guī)則) -s 來源 -p 指定協(xié)議tcp 或者udp –sport 端口1234 -d 目標(biāo)ip –dport 目標(biāo)端口 -j 具體操作 dorp 拒絕(數(shù)據(jù)包來了,看都不看直接扔掉) reject