差異處
這裏顯示兩個版本的差異處。
兩邊的前次修訂版 前次修改 下次修改 | 前次修改 | ||
tech:centos7_network [2018/07/20 14:46] – [修改 DNS 設定] Jonathan Tsai | tech:centos7_network [2021/09/11 14:57] (目前版本) – [FirewallD (取代 iptables)] jonathan | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== CentOS7 網路相關整理 ====== | ||
+ | 可先透過 https:// | ||
+ | |||
+ | ===== 沒有 ifconfig 命令問題 ===== | ||
+ | <code sh> | ||
+ | yum install net-tools | ||
+ | </ | ||
+ | ++++ 安裝紀錄|< | ||
+ | [root@centos7-tmp ~]# yum install net-tools | ||
+ | Loaded plugins: fastestmirror | ||
+ | base | 3.6 kB 00:00 | ||
+ | extras | ||
+ | updates | ||
+ | (1/4): base/ | ||
+ | (2/4): extras/ | ||
+ | (3/4): updates/ | ||
+ | (4/4): base/ | ||
+ | Determining fastest mirrors | ||
+ | * base: ftp.yzu.edu.tw | ||
+ | * extras: ftp.yzu.edu.tw | ||
+ | * updates: ftp.yzu.edu.tw | ||
+ | Resolving Dependencies | ||
+ | --> Running transaction check | ||
+ | ---> Package net-tools.x86_64 0: | ||
+ | --> Finished Dependency Resolution | ||
+ | |||
+ | Dependencies Resolved | ||
+ | |||
+ | ================================================================================ | ||
+ | | ||
+ | ================================================================================ | ||
+ | Installing: | ||
+ | | ||
+ | |||
+ | Transaction Summary | ||
+ | ================================================================================ | ||
+ | Install | ||
+ | |||
+ | Total download size: 304 k | ||
+ | Installed size: 917 k | ||
+ | Is this ok [y/d/N]: y | ||
+ | Downloading packages: | ||
+ | 警告:/ | ||
+ | Public key for net-tools-2.0-0.17.20131004git.el7.x86_64.rpm is not installed | ||
+ | net-tools-2.0-0.17.20131004git.el7.x86_64.rpm | ||
+ | Retrieving key from file:/// | ||
+ | Importing GPG key 0xF4A80EB5: | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | Is this ok [y/N]: y | ||
+ | Running transaction check | ||
+ | Running transaction test | ||
+ | Transaction test succeeded | ||
+ | Running transaction | ||
+ | Installing : net-tools-2.0-0.17.20131004git.el7.x86_64 | ||
+ | Verifying | ||
+ | |||
+ | Installed: | ||
+ | net-tools.x86_64 0: | ||
+ | |||
+ | Complete! | ||
+ | </ | ||
+ | ++++ 執行紀錄 |< | ||
+ | [root@centos7-tmp ~]# ifconfig | ||
+ | ens3: flags=4163< | ||
+ | inet 192.168.0.104 | ||
+ | inet6 fe80:: | ||
+ | ether 52: | ||
+ | RX packets 12252 bytes 16348084 (15.5 MiB) | ||
+ | RX errors 0 dropped 0 overruns 0 frame 0 | ||
+ | TX packets 7298 bytes 570168 (556.8 KiB) | ||
+ | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 | ||
+ | |||
+ | ens4: flags=4163< | ||
+ | ether 52: | ||
+ | RX packets 49 bytes 3016 (2.9 KiB) | ||
+ | RX errors 0 dropped 0 overruns 0 frame 0 | ||
+ | TX packets 0 bytes 0 (0.0 B) | ||
+ | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 | ||
+ | |||
+ | lo: flags=73< | ||
+ | inet 127.0.0.1 | ||
+ | inet6 ::1 prefixlen 128 scopeid 0x10< | ||
+ | loop txqueuelen 0 (Local Loopback) | ||
+ | RX packets 0 bytes 0 (0.0 B) | ||
+ | RX errors 0 dropped 0 overruns 0 frame 0 | ||
+ | TX packets 0 bytes 0 (0.0 B) | ||
+ | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 | ||
+ | |||
+ | </ | ||
+ | * 參考網址 - http:// | ||
+ | * https:// | ||
+ | |||
+ | ===== FirewallD (取代 iptables) ===== | ||
+ | * 取得 zome <code sh> | ||
+ | * 查看目前開放的服務 <code sh> | ||
+ | * 新增臨時開放的服務 <code sh> | ||
+ | * 查看永久開放的服務 <code sh> | ||
+ | * 新增永久開放的服務 <code sh> | ||
+ | < | ||
+ | * 如果是直接修改 / | ||
+ | * Exp. / | ||
+ | * 更改後可以透過 <code sh> | ||
+ | firewall-cmd --complete-reload | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | * 啟用與關閉 firewalld <cli> | ||
+ | [root@jonathan-vm1 ~]# firewall-cmd --get-default-zone | ||
+ | FirewallD is not running | ||
+ | [root@jonathan-vm1 ~]# systemctl start firewalld | ||
+ | [root@jonathan-vm1 ~]# systemctl enable firewalld | ||
+ | Created symlink / | ||
+ | Created symlink / | ||
+ | [root@jonathan-vm1 ~]# firewall-cmd --get-default-zone | ||
+ | public | ||
+ | [root@jonathan-vm1 ~]# firewall-cmd --list-services | ||
+ | cockpit dhcpv6-client ssh | ||
+ | [root@jonathan-vm1 ~]# systemctl stop firewalld | ||
+ | [root@jonathan-vm1 ~]# systemctl disable firewalld | ||
+ | Removed / | ||
+ | Removed / | ||
+ | [root@jonathan-vm1 ~]# systemctl list-unit-files | grep firewalld | ||
+ | firewalld.service | ||
+ | </ | ||
+ | |||
+ | ===== netstat 的替代語法 ss ===== | ||
+ | * 看 listen port :<code sh>ss -l -n</ | ||
+ | # ss -l -n | grep 25 | ||
+ | tcp LISTEN | ||
+ | tcp LISTEN | ||
+ | </ | ||
+ | * 看 TCP 連線 :<code sh>ss -t -n</ | ||
+ | # ss -t -n | grep 143 | ||
+ | ESTAB 0 0 192.168.0.236: | ||
+ | ESTAB 0 0 192.168.0.236: | ||
+ | ESTAB 0 0 192.168.0.236: | ||
+ | ESTAB 0 0 192.168.0.236: | ||
+ | : | ||
+ | ESTAB 0 0 192.168.0.236: | ||
+ | </ | ||
+ | |||
+ | ===== 修改 IP 設定 ===== | ||
+ | * Exp 修改 eth0 IP 為 192.168.1.28 | ||
+ | - <code h vi / | ||
+ | : | ||
+ | BOOTPROTO=static | ||
+ | IPADDR=192.168.1.28 | ||
+ | NETMASK=255.255.255.0 | ||
+ | GATEWAY=192.168.1.254 | ||
+ | : | ||
+ | DNS1=192.168.1.254 | ||
+ | DNS2=101.101.101.101 | ||
+ | </ | ||
+ | - <code sh> | ||
+ | |||
+ | ===== 查看現在的 IP 與 route ===== | ||
+ | * <code sh> | ||
+ | ip a | ||
+ | ip route list | ||
+ | </ | ||
+ | |||
+ | ===== 修改 DNS 設定 ===== | ||
+ | * 直接改 / | ||
+ | * Exp. 要設定網卡 eth0 的 DNS 為 192.168.11.242 與 168.95.192.1 <code sh> | ||
+ | nmcli con mod eth0 ipv4.dns " | ||
+ | nmcli con up eth0 | ||
+ | </ | ||
+ | |||
+ | ===== 關閉 IPv6 的方式 ===== | ||
+ | * 因為很多服務會認來源 IP (Exp. Mail Server), 因此避免來源 IP 變成 IPv6 造成問題, | ||
+ | * 在 / | ||
+ | : | ||
+ | net.ipv6.conf.all.disable_ipv6 = 1 | ||
+ | net.ipv6.conf.default.disable_ipv6 = 1 | ||
+ | </ | ||
+ | * 下命令生效 <code sh> | ||
+ | sysctl -p | ||
+ | </ | ||
+ | * 最好重開機 | ||
+ | |||
+ | ===== 參考網址 ===== | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * https:// | ||
+ | * [[https:// | ||
+ | * https:// | ||
+ | |||
+ | {{tag> | ||