ifconfig 命令查看網卡網絡信息,好比ip、網關、子網掩碼等,可是安裝centos7的版本或者某些未知緣由,此命令提示找不到,咱們可使用Yum安裝:linux
yum install -y net-tools
使用 ifconfig 命令查看vim
ifconfig
選項:centos
ifconfig -a
或者某些時候咱們也可使用 ** ip add ** 命令來查看信息,實際比較仍是以爲ifconfig命令顯示的清楚一點。安全
ip add
重啓某個指定網卡(ifdown表示關閉某網卡,ifup表示啓用某網卡)網絡
ifdown ens33 ; ifup ens33 #第1種方式 ifdown ens33 && ifup ensss #第2種方式
因爲使用遠程登陸,因此不建議單獨使用** ifdown **命令,至於爲何要重啓某網卡而不是重啓服務呢,由於假如你只修改了此網卡的部分信息,不想直接重啓服務影響其餘網卡的使用,因此能夠 **ifdown **和 **ifup **結合使用表示重啓;tcp
1.進入網卡配置文件目錄工具
[root@yolks1 ~]# cd /etc/sysconfig/network-scripts/
2拷貝文件當前ens33網卡配置文件測試
[root@yolks1 network-scripts]# cp ifcfg-ens33 ifcfg-ens33\:1 #前面的右斜槓表示脫義冒號
3.編輯新複製的網卡配置文件:ifcfg-ens33:1centos7
vim ifcfg-ens33:1
修改如下標註的地方,刪除掉DNS和GATEWAY所在的行rest
4.重啓 ** dns33 ** 網卡
[root@yolks1 network-scripts]# ifdown ens33 && ifup ens33 成功斷開設備 'ens33'。 鏈接已成功激活(D-Bus 活動路徑:/org/freedesktop/NetworkManager/ActiveConnection/5)
5.** ifconfig ** 查看新配置的網卡信息
6.測試本地能不能ping通虛擬網卡
1.mii-tool 命令以下:
[root@yolks1 network-scripts]# mii-tool ens33:1 ens33:1: negotiated 1000baseT-FD flow-control, link ok
判斷輸出的是不是** link ok** 若是是,則說明網絡鏈接暢通無誤;若是輸出的是** no link **則表示網卡沒鏈接;
2.若是上面的 mii-tool 執行提示找不到,也可使用** ethtool 網卡名稱 **來查看結果的最後一行 **Link detected **是不是 yes 或者是 ** no ** 來表示網卡鏈接是否正常
hostnamectl set-hostname new-hostname
修改以後須要從新鏈接便可看到變化;
DNS配置文件路徑 : /etc/resolv.conf
[root@yolks-001 ~]# cat /etc/resolv.conf #查看當前dns配置 # Generated by NetworkManager nameserver 119.29.29.29 [root@yolks-001 ~]# vi !$ vi /etc/resolv.conf #編輯並添加新的一行nameserver 8.8.8.8 [root@yolks-001 ~]# cat /etc/resolv.conf #再次查看新的dns配置 # Generated by NetworkManager nameserver 119.29.29.29 nameserver 8.8.8.8
可是要知道編輯上面此文件保存dns的話是臨時的,永久保存的話直接修改 **/etc/sysconfig/network-scripts/ifcfg-ens33 **添加DNS紀錄便可;
修改 /etc/hosts 文件,添加一行新的解析
測試ping,顯示爲修改的配置ip,而且只有本機纔會生效
hosts文件格式很簡單,注意如下幾點;
1.SELinux是linux系統特有的安全機制。由於這種機制的限制太多,配置也繁瑣,因此幾乎沒有人真正的應用它,安裝完系統咱們通常都把SELinux關閉,以避免引發沒必要要的麻煩。
臨時關閉:
setenforce 0
永久關閉:
vim /etc/selinux/config #編輯此文件
修改 SELINUX=disabled,重啓機器便可
查看 SELINUX 狀態:
[root@yolks-001 ~]# getenforce Disabled
2.關係圖以下:
查看centos版本
[root@yolks-001 ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core)
1.關閉firewalld
[root@yolks-001 ~]# systemctl disable firewalld Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
2.中止firewalld
[root@yolks-001 ~]# systemctl stop firewalld
3.yum安裝iptables工具
yum install -y iptables-services
4.讓iptables服務開機啓動
[root@yolks-001 ~]# systemctl enable iptables Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
5.開啓iptables服務
[root@yolks-001 ~]# systemctl start iptables
6.使用iptables查看默認規則
iptables -nvL
netfilter的5個表
netfilter的5個鏈
參考圖
圖片來源於Askz的博客
圖片來源於Askz的博客
1.查看iptables默認規則配置文件:
cat /etc/sysconfig/iptables
2.查看iptables默認規則:
iptables -nvL
3.保存iptables規則(當前規則,保存到配置文件):
service iptables save
4.清空iptables規則:
iptables -F
5.重啓iptables規則
service iptables restart
6.查看指定表的規則
iptables -t nat -nvL
7.清空表的計數器
iptables -Z
8.若是不加-t選項則默認的表爲fliter表,經常使用的選項以下: