• ifconfig查看網卡ip(yum install net-tools)
• ifup ens33/ifdown ens33
• 設定虛擬網卡ens33:1
• mii-tool ens33 查看網卡是否鏈接
• ethtool ens33 也能夠查看網卡是否鏈接
• 更改主機名 hostnamectl set-hostname aminglinux
• DNS配置文件/etc/resolv.conf
• /etc/hosts文件html
ifconfig 查看網卡的IP,centos6默認就有,centos7沒有,須要安裝一個包net-tools
yun install -y net-toollinux
ip add 也能夠查看網卡ios
ifconfig -a 在你網卡宕掉的時候或者沒有IP的時候,ifconfig是查看不了的,用-a是能夠查看到的。vim
ifdown ens33 關閉和啓動網卡ens33centos
ifdown ens33;ifup ens33 這個命令在那些狀況下使用呢?
在針對某個網卡進行更改,好比DNS等,更改完後須要重啓服務,可是我不想把全部的網卡都重啓,這個時候,就可使用ifdown和ifup來單獨重啓這個網卡.服務器
ifdown ens33 &&ifup ens33 重啓網卡網絡
增長一個ip怎麼作呢?
首先增長一個虛擬網卡,在虛擬網卡上添加一個IP
先到網卡配置文件裏面,拷貝一個虛擬網卡dom
[root@localhost ~]# cd /etc/sysconfig/network-scripts/ [root@localhost network-scripts]# cp ifcfg-enss ifcfg-enss\:0 [root@localhost network-scripts]# vim ifcfg-ens33:0
重啓下網卡socket
# ifdown ens33 &&ifup ens33
在window上ping這個IPtcp
虛擬網卡會在lvs,keepalived 上用到。
查看某臺電腦網線是否正常 mii-tool ens33
若是mii-tool 提示no link 能夠用ethtool 來查看網卡是否正常
也能夠用 ethtool ens33 來查看網卡是否正常
hostnamectl set-hostname aminglinux 更改主機名 centos7獨有的
[root@yong-02 ~]# hostnamectl set-hostname yongge-02
hostname 查看主機名
[root@yong-02 ~]# hostname yongge-02
主機名的配置文件 /etc/hostname
[root@yong-02 ~]# cat /etc/hostname yongge-02
若是想要生效,能夠從新登陸一下
DNS的配置文件 /etc/resolv.conf
dns是在配置網卡的時候寫的。配置文件裏面修改DNS是臨時的,重啓後就不能生效了,因此要去網卡配置裏面修改DNS。
域名解析 /etc/hosts 只在本機上生效 加入192.168.180.135 www.qq.com 解析到本機IP
能夠一個IP多個域名;用空格隔開 ;
若是是一個域名多個IP,只生效最後IP.
• selinux臨時關閉 setenforce 0
• selinux永久關閉 vi /etc/selinux/config
• centos7以前使用netfilter防火牆
• centos7開始使用firewalld防火牆
• 關閉firewalld開啓netfilter方法
• systemctl stop firewalld
• systemctl disable firewalled
• yum install -y iptables-services
• systemctl enable iptables
• systemctl start iptables
編輯配置文件 /etc/selinux/config,SELINUX=disabled ,而後重啓服務
臨時關閉selinux setenforce 0
Enforcing 強制模式,表明 SELinux 運做中,且已經正確的開始限制 domain/type 了
Permissive 寬容模式:表明 SELinux 運做中,不過僅會有警告訊息並不會實際限制 domain/type 的存取
disabled:關閉,SELinux 並無實際運做。
linux防火牆 netfilter是centos5,6自帶的
linux防火牆 firewalld是centos7的自帶的
centios7裏面也可使用 netfilter,那麼怎麼使用呢?
1)首先關閉contos7自帶的firewalld
systemctl disable firewalld
2)關閉服務
3)打開netfilter,打開前先安裝一個包 iptables-services
4)開啓服務
5)iptables -nvL 查看規則
[root@yong-02 ~]# man iptables 查看五個表 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 new connection 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 routing), and POSTROUTING (for altering packets as they are about to go out). IPv6 NAT support is available since kernel 3.7. mangle: This table is used for specialized packet alteration. Until kernel 2.4.17 it had two built-in chains: PREROUTING (for altering incom‐ ing packets before routing) and OUTPUT (for altering locally-gener‐ ated packets before routing). Since kernel 2.4.18, three other built-in chains are also supported: INPUT (for packets coming into the box itself), FORWARD (for altering packets being routed through the box), and POSTROUTING (for altering packets as they are about to go out). raw: This table is used mainly for configuring exemptions from connec‐ tion tracking in combination with the NOTRACK target. It registers at the netfilter hooks with higher priority and is thus called before ip_conntrack, or any other IP tables. It provides the fol‐ lowing built-in chains: PREROUTING (for packets arriving via any network interface) OUTPUT (for packets generated by local pro‐ cesses) security: This table is used for Mandatory Access Control (MAC) networking rules, such as those enabled by the SECMARK and CONNSECMARK tar‐ gets. Mandatory Access Control is implemented by Linux Security Modules such as SELinux. The security table is called after the filter table, allowing any Discretionary Access Control (DAC) rules in the filter table to take effect before MAC rules. This table provides the following built-in chains: INPUT (for packets coming into the box itself), OUTPUT (for altering locally-generated pack‐ ets before routing), and FORWARD (for altering packets being routed through the box).
[root@yong-02 ~]# iptables -nvL //查看iptables規則 Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 357 28956 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 2 184 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 18 1404 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT 251 packets, 57368 bytes) pkts bytes target prot opt in out source destination [root@hf-01 ~]#
[root@yong-02 ~]# service iptables restart Redirecting to /bin/systemctl restart iptables.service
[root@yong-02 ~]# 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
[root@yong-02 ~]# iptables -F [root@yong-02 ~]# iptables -nvL Chain INPUT (policy ACCEPT 14 packets, 924 bytes) pkts bytes target prot opt in out source destination Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 8 packets, 768 bytes) pkts bytes target prot opt in out source destination
service iptables save 保存規則
在iptables -F清空規則後,重啓service restart iptables.service(重啓服務器或者iptables規則),都會加載配置文件裏面的規則
[root@yong-02 ~]# service iptables restart Redirecting to /bin/systemctl restart iptables.service [root@yong-02 ~]# iptables -nvL Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 6 396 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT 4 packets, 480 bytes) pkts bytes target prot opt in out source destination
[root@yong-02 ~]# iptables -Z ; iptables -nvL Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination
[root@yong-02 ~]# iptables -t filter -nvL Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 4 280 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT 3 packets, 1396 bytes) pkts bytes target prot opt in out source destination
[root@yong-02 ~]# iptables -A INPUT -s 192.168.188.1 -p tcp --sport 1234 -d 192.168.188.128 --dport 80 -j DROP //新增規則 [root@yong-02 ~]# iptables -nvL Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 21 1508 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 1 229 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited 0 0 DROP tcp -- * * 192.168.188.1 192.168.188.128 tcp spt:1234 dpt:80 Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT 6 packets, 872 bytes) pkts bytes target prot opt in out source destination
[root@yong-02 ~]# iptables -I INPUT -p tcp --dport 80 -j DROP [root@yong-02 ~]# iptables -nvL Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 DROP tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 32 2276 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 1 229 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited 0 0 DROP tcp -- * * 192.168.188.1 192.168.188.128 tcp spt:1234 dpt:80 Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT 4 packets, 512 bytes) pkts bytes target prot opt in out source destination [root@hf-01 ~]#
[root@yong-02 ~]# iptables -D INPUT -p tcp --dport 80 -j DROP //刪除規則 [root@yong-02 ~]# iptables -D INPUT -s 192.168.188.1 -p tcp --sport 1234 -d 192.168.188.128 --dport 80 -j DROP //刪除規則 [root@yong-02 ~]# iptables -nvL Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 243 18884 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 2 462 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT 5 packets, 908 bytes) pkts bytes target prot opt in out source destination
[root@yong-02 ~]# iptables -nvL --line-number Chain INPUT (policy ACCEPT 0 packets, 0 bytes) num pkts bytes target prot opt in out source destination 1 396 31108 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 2 0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 3 0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 4 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 5 2 462 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited 6 0 0 DROP tcp -- * * 192.168.188.1 192.168.188.128 tcp spt:1234 dpt:80 Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) num pkts bytes target prot opt in out source destination 1 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT 4 packets, 656 bytes) num pkts bytes target prot opt in out source destination [root@yong-02 ~]# iptables -D INPUT 6 //刪除序列6的規則 [root@yong-02 ~]# iptables -nvL --line-number Chain INPUT (policy ACCEPT 0 packets, 0 bytes) num pkts bytes target prot opt in out source destination 1 455 35012 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 2 0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 3 0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 4 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 5 2 462 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) num pkts bytes target prot opt in out source destination 1 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT 4 packets, 432 bytes) num pkts bytes target prot opt in out source destination
iptables -P OUTPUT DROP 默認的規則
默認的規則最好不要去改變!!!