5,6版本:system-config-network(setup)
配置文件位置:/etc/sysconfig/network-scripts/ifcfg-eth[0-n]
7版本:nmcil nmtui(圖形界面)
配置文件位置:/etc/sysconfig/network-scripts/ifcfg-en*****
ifcfg-eth0,ifcfg-en******網(wǎng)絡(luò)配置文件信息
TYPE=Ethernet #接口類型為以太網(wǎng)卡 BOOTPROTO=none #獲取地址協(xié)議dhcp(自動獲取),static(手動配置),none HWADDR=00:0C:29:75:A1:89 #網(wǎng)卡MAC UUID=be9d332f-ae79-42b6-8040-d2d431e4e195 #網(wǎng)卡標識 #DEVICE=eno16777736 #7系列的網(wǎng)卡名稱 DEVICE=eth0 #5,6系列的網(wǎng)卡名 ONBOOT=yes #開機自動激活網(wǎng)卡,no不激活 IPADDR=10.76.249.91 GATEWAY=10.76.249.2 NETMASK=255.255.255.0 DNS=8.8.4.4 |
臨時添加IP地址,重啟后失效
ip addr add 192.168.1.150/24 dev eth0 或者 # ifconfig eth0 192.168.1.150/24 up #重啟后會失效,第一張網(wǎng)卡為eth0,第二張為eth2依此類推 # ifconfig eth0 1.1 Link encap:Ethernet HWaddr 00:0C:29:75:A1:89 inet addr:192.168.1.150 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe75:a189/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5682 errors:0 dropped:0 overruns:0 frame:0 TX packets:4136 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:412252 (402.5 KiB) TX bytes:4464715 (4.2 MiB) |
# ip route add default via 192.168.1.1 #default via 192.168.1.1devinterface |
# ip addr show 1: lo: link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eno16777736: link/ether 200:0c:29:e1:c5:8a brd ff:ff:ff:ff:ff:ff inet 310.76.249.91/24 brd 10.76.249.255 scope global eno16777736 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fee1:c58a/64 scope link valid_lft forever preferred_lft forever 1:網(wǎng)卡狀態(tài)已經(jīng)啟動 2:網(wǎng)卡的mac地址 3:網(wǎng)卡”eno16777736”地址 或者 # ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:75:A1:89 inet addr:192.168.1.150 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe75:a189/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:6386 errors:0 dropped:0 overruns:0 frame:0 TX packets:4436 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:467110 (456.1 KiB) TX bytes:4502451 (4.2 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:66 errors:0 dropped:0 overruns:0 frame:0 TX packets:66 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:3482 (3.4 KiB) TX bytes:3482 (3.4 KiB) 或者 # nmcli dev show eth0 GENERAL.設(shè)備: eth0 GENERAL.類型: ethernet GENERAL.硬盤: 00:0C:29:E1:C5:8A GENERAL.MTU: 1500 GENERAL.狀態(tài): 100 (連接的) GENERAL.CONNECTION: eno16777736 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 WIRED-PROPERTIES.容器: 開 IP4.地址[1]: 10.76.249.91/24 IP4.網(wǎng)關(guān): 10.76.249.2 IP6.地址[1]: fe80::20c:29ff:fee1:c58a/64 IP6.網(wǎng)關(guān): |
# ip -s link show eth0 2: eth0: link/ether 00:0c:29:75:a1:89 brd ff:ff:ff:ff:ff:ff RX: bytes packets errors dropped overrun mcast 477844 6528 0 0 0 0 TX: bytes packets errors dropped carrier collsns 4508951 4492 0 0 0 0 或者 # ifconfig –s eth0 Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg eth0 1500 0 6459 0 0 0 4455 0 0 0 BMRU |
#ip route default via 10.76.249.2 dev eth0 proto static metric 100 10.76.249.0/24 dev eth0 proto kernel scope link src 10.76.249.91 metric 100 |
常用到的選項
ss和netstat使用方法相似,但是ss效率要比較高,消耗性能比較少。
選項 | 功能 |
-l | 監(jiān)聽狀態(tài)的連接 |
-n | 不解析服務(wù)名以數(shù)字顯示 |
-t | 顯示TCP連接 |
-u | 顯示UDP連接 |
-a | 顯示所有狀態(tài) |
-p | 顯示以哪個進程發(fā)起的連接 |
常用的組合
-tan,-tanl, -tanlp, -uan
幾種狀態(tài)信息
State: LISTEN(監(jiān)聽),ESTAB(已建立的鏈接)
# ss -tna State Recv-Q Send-Q Local Address:Port 本地端口 Peer Address:Port 客戶端端口 LISTEN 0 128 :::22 :::* LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:6010 *:* LISTEN 0 128 ::1:6010 :::* LISTEN 0 128 127.0.0.1:6011 *:* LISTEN 0 128 ::1:6011 :::* LISTEN 0 128 127.0.0.1:6012 *:* LISTEN 0 128 ::1:6012 :::* LISTEN 0 128 127.0.0.1:6013 *:* LISTEN 0 128 ::1:6013 :::* ESTAB 0 0 192.168.1.106:22 192.168.1.103:63167 ESTAB 0 0 192.168.1.150:22 192.168.1.103:63753 ESTAB 0 52 192.168.1.150:22 192.168.1.103:54953 ESTAB 0 0 192.168.1.106:22 192.168.1.103:63134 |
修改網(wǎng)卡文件內(nèi)容
# cat /etc/sysconfig/network-scripts/ifcfg- eno16777736 TYPE=Ethernet BOOTPROTO=none DEFROUTE=yes PEERDNS=yes PEERROUTES=yes NAME=eno16777736 UUID=be9d332f-ae79-42b6-8040-d2d431e4e195 #DEVICE=eno16777736 #注釋掉原來的命名 DEVICE=eth0 #傳統(tǒng)命名 ONBOOT=yes IPADDR=10.76.249.91 GATEWAY=10.76.249.2 NETMASK=255.255.255.0 |
重命名網(wǎng)卡文件
# mv /etc/sysconfig/network-scripts/ifcfg-eno16777736 /etc/sysconfig/network-scripts/ifcfg-eth0 |
編輯/etc/default/grub配置文件
# vim /etc/default/grub GRUB_TIMEOUT=5 GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" #GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet" #修改前 GRUB_CMDLINE_LINUX="net.ifnames=0 rhgb quiet" #修改后 GRUB_DISABLE_RECOVERY="true" |
為grub2生成其配置文件
# grub2-mkconfig -o /etc/grub2.cfg Generating grub configuration file ... Found linux p_w_picpath: /boot/vmlinuz-3.10.0-229.el7.x86_64 Found initrd p_w_picpath: /boot/initramfs-3.10.0-229.el7.x86_64.img Found linux p_w_picpath: /boot/vmlinuz-0-rescue-16de415bcbd643d886010c2fe954d9cb Found initrd p_w_picpath: /boot/initramfs-0-rescue-16de415bcbd643d886010c2fe954d9cb.img done |
重啟系統(tǒng)
驗證結(jié)果
# ip addr show eth0 2: eth0: link/ether 00:0c:29:e1:c5:8a brd ff:ff:ff:ff:ff:ff inet 10.76.249.91/24 brd 10.76.249.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fee1:c58a/64 scope link valid_lft forever preferred_lft forever |
nmcli:網(wǎng)絡(luò)管理命令行接口:NetworkManagerCommand-Line Interface
nmtui:網(wǎng)絡(luò)管理文本用戶接口:NetworkManager Text-User Interface
RHEL7之后的網(wǎng)絡(luò)配置命令
[root@localhost conf.d]# nmcli --help Usage: nmcli [OPTIONS] OBJECT { COMMAND | help } OPTIONS -t[erse] terse output -p[retty] pretty output -m[ode] tabular|multiline output mode -f[ields] -e[scape] yes|no escape columns separators in values -n[ocheck] don't check nmcli and NetworkManager versions -a[sk] ask for missing parameters -w[ait] -v[ersion] show program version -h[elp] print this help OBJECT g[eneral] NetworkManager's general status and operations n[etworking] overall networking control r[adio] NetworkManager radio switches c[onnection] NetworkManager's connections 簡寫為c d[evice] devices managed by NetworkManager 簡寫為d a[gent] NetworkManager secret agent or polkit agent |
重新加載網(wǎng)絡(luò)配置文件
[root@localhost ~]# nmcli c reload
[root@localhost ~]# nmcli c load/etc/sysconfig/network-scripts/ifcfg-eth0
配置IP地址
[root@localhost ~]# nmcli con mod eno16777736 ipv4.addresses '192.168.1.119/24' 網(wǎng)卡名使用查看# nmcli con show |
配置DNS
[root@localhost ~]# nmcli con mod eno16777736 ipv4.dns '8.8.4.4' |
配置網(wǎng)關(guān)
[root@localhost ~]# nmcli con mod eno16777736 ipv4.gateway '192.168.1.1' |
停啟用網(wǎng)卡
[root@localhost ~]# nmcli dev dis eth0 dis 為 disconnect [root@localhost ~]# nmcli con up eth0 |
查看相關(guān)信息
[root@localhost ~]# nmcli device status DEVICE TYPE STATE CONNECTION eth0 ethernet connected eno16777736 lo loopback unmanaged -- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
nmtui 圖形配置界面比較簡潔
[root@localhost ~]# nmtui
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。