Linux 網(wǎng)卡配置

Linux 網(wǎng)卡配置有兩種方法,一是臨時(shí)配置、二是永久配置。

1. 臨時(shí)配置

臨時(shí)配置網(wǎng)卡(以網(wǎng)卡名為eth0為例)的IP地址和子網(wǎng)掩碼,在重啟后失效。
1.1使用ifconfig命令配置,命令如下:

ifconfig eth0 192.168.33.15 netmask 255.255.255.0

配置完成后,使用ifconfig命令查看是否配置成功,得到:

root@ubuntu:~# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.33.15  netmask 255.255.255.0  broadcast 192.168.33.255
        inet6 fe80::fab1:56ff:feb5:8  prefixlen 64  scopeid 0x20<link>
        ether f8:b1:56:b5:00:08  txqueuelen 1000  (Ethernet)
        RX packets 988079  bytes 161803321 (161.8 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1849659  bytes 2584022279 (2.5 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 9474363  bytes 997142730 (997.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 9474363  bytes 997142730 (997.1 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

其中,網(wǎng)卡lo為本地環(huán)回網(wǎng)卡。

使用route命令配置網(wǎng)關(guān),命令如下:

route add default gw 192.168.33.31

若網(wǎng)卡 eth0 未啟用,可使用命令ifconfig eth0 up啟用;用命令ifconfig eth0 down禁用網(wǎng)卡。

2. 永久配置

編輯/etc/network/interfaces文件。命令如下:

vi /etc/network/interfaces

按下按鍵io進(jìn)入插入模式,編輯結(jié)束后使用Esc退出編輯,分別按鍵:wq退出。

例如:該interfaces的內(nèi)容可能為:

# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
# Generated by debian-installer.

# The loopback interface
auto lo
iface lo inet loopback

或者設(shè)置靜態(tài)IP地址。

auto eth0
iface eth0 int static
address 192.168.33.16
netmask 255.255.255.0
gateway 192.168.33.31

或者默認(rèn)通過DHCP模式獲得網(wǎng)絡(luò)配置。

auto eth0
iface eth0 int dhcp

配置后用命令行/etc/init.d/networking restart重啟網(wǎng)絡(luò)服務(wù)或重啟計(jì)算機(jī)生效。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 如果設(shè)置雙網(wǎng)卡,把ONBOOT都設(shè)置為yes.重啟網(wǎng)卡 一. centos7.4 設(shè)置網(wǎng)卡 打開網(wǎng)卡配置文件 # ...
    Joncc閱讀 20,087評(píng)論 3 6
  • 配置文件位置:/etc/sysconfig/network-scripts/ifcfg-eth0 \1. DEVI...
    August________閱讀 308評(píng)論 0 3
  • 轉(zhuǎn)自:https://www.cnblogs.com/ienino/p/7717092.html 配置文件位置:/...
    H0f_9閱讀 1,665評(píng)論 0 0
  • 1.命令格式:ifconfig [網(wǎng)絡(luò)設(shè)備] [參數(shù)] 2.命令功能: ifconfig 命令用來查看和配置網(wǎng)絡(luò)設(shè)...
    Nuuuu閱讀 4,154評(píng)論 0 12
  • 進(jìn)入帶空格的文件或者文件夾 Linux文件權(quán)限詳解 文件和目錄權(quán)限概述 在linux中的每一個(gè)文件或目錄都包含有訪...
    annkee閱讀 2,794評(píng)論 0 4

友情鏈接更多精彩內(nèi)容