您好,登錄后才能下訂單哦!
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******網絡配置文件信息
TYPE=Ethernet #接口類型為以太網卡 BOOTPROTO=none #獲取地址協議dhcp(自動獲取),static(手動配置),none HWADDR=00:0C:29:75:A1:89 #網卡MAC UUID=be9d332f-ae79-42b6-8040-d2d431e4e195 #網卡標識 #DEVICE=eno16777736 #7系列的網卡名稱 DEVICE=eth0 #5,6系列的網卡名 ONBOOT=yes #開機自動激活網卡,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 #重啟后會失效,第一張網卡為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.1 devinterface |
# ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 disc noqueue state UNKNOWN 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: <BROADCAST,MULTICAST,1UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 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:網卡狀態已經啟動 2:網卡的mac地址 3:網卡”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.設備: eth0 GENERAL.類型: ethernet GENERAL.硬盤: 00:0C:29:E1:C5:8A GENERAL.MTU: 1500 GENERAL.狀態: 100 (連接的) GENERAL.CONNECTION: eno16777736 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 WIRED-PROPERTIES.容器: 開 IP4.地址[1]: 10.76.249.91/24 IP4.網關: 10.76.249.2 IP6.地址[1]: fe80::20c:29ff:fee1:c58a/64 IP6.網關: |
# ip -s link show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 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 | 監聽狀態的連接 |
-n | 不解析服務名以數字顯示 |
-t | 顯示TCP連接 |
-u | 顯示UDP連接 |
-a | 顯示所有狀態 |
-p | 顯示以哪個進程發起的連接 |
常用的組合
-tan,-tanl, -tanlp, -uan
幾種狀態信息
State: LISTEN(監聽),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 |
修改網卡文件內容
# 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 #傳統命名 ONBOOT=yes IPADDR=10.76.249.91 GATEWAY=10.76.249.2 NETMASK=255.255.255.0
|
重命名網卡文件
# 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
|
重啟系統
驗證結果
# ip addr show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 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:網絡管理命令行接口:NetworkManagerCommand-Line Interface
nmtui:網絡管理文本用戶接口:NetworkManager Text-User Interface
RHEL7之后的網絡配置命令
[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] <field1,field2,...>|all|common specify fields to output -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] <seconds> set timeout waiting for finishing operations -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 |
重新加載網絡配置文件
[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' 網卡名使用查看# nmcli con show |
配置DNS
[root@localhost ~]# nmcli con mod eno16777736 ipv4.dns '8.8.4.4' |
配置網關
[root@localhost ~]# nmcli con mod eno16777736 ipv4.gateway '192.168.1.1' |
停啟用網卡
[root@localhost ~]# nmcli dev dis eth0 dis 為 disconnect [root@localhost ~]# nmcli con up eth0
|
查看相關信息
[root@localhost ~]# nmcli device status DEVICE TYPE STATE CONNECTION eth0 ethernet connected eno16777736 lo loopback unmanaged -- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
nmtui 圖形配置界面比較簡潔
[root@localhost ~]# nmtui
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。