Linux網絡基本配置命令


修改方法:

  • 命令方式,大多是立即生效、臨時有效;
  • GUI圖形方式,
  • 修改配置文件,重啟服務有效

1、修改主機名

hostname查看
hostname name臨時修改
hostnamectl set-hostname name永久有效(cnetos7)
centos7 /etc/hostname
centos6 /etc/sysconfig/network

2、網絡接口配置

  • vi修改配置文件
  • ifconfig查看或設置網卡的TCP/IP參數
[lixn@localhost ~]$ ifconfig
enp0s31f6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500        enp0/etho第一塊物理網卡    mtu分組的最大傳送單元  flags網絡接口狀態up....(活動)
        inet 192.168.1.125  netmask 255.255.255.0  broadcast 192.168.1.255   inet/inet addr網卡的IP地址   netmask/Mask子網掩碼    boadcast/bcast廣播地址
        inet6 fe80::c133:9f47:a9f:66  prefixlen 64  scopeid 0x20<link>    ine網卡IPv6
        ether c8:5b:76:25:af:01  txqueuelen 1000  (Ethernet)          ether/Hwaddr網卡的物理地址mac地址  txqueuelen傳送隊列的長度
        RX packets 4673305  bytes 3223334449 (3.0 GiB)             RX packets接受的數據包總數
        RX errors 0  dropped 0  overruns 0  frame 0               
        TX packets 2439350  bytes 305949223 (291.7 MiB)             TX packets發送的數據包總數
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0xe1300000-e1320000  

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 1  (Local Loopback)
        RX packets 45571  bytes 3060724 (2.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 45571  bytes 3060724 (2.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlp1s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b8:81:98:5a:7f:17  txqueuelen 1000  (Ethernet)
        RX packets 1284454  bytes 1267419395 (1.1 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 913186  bytes 155893700 (148.6 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
當前有3個網絡接口信息,一個是enp0是系統的第一塊網卡信息;lo代表loopback環回接口,是Linux內部通信的基礎,IP始終為127.0.0.1;
ifconfig 網卡名 <IP地址> netmask <子網掩碼>  此命令會立即生效,但不會修改配置文件。
ifconfig eth0 192.168.1.10 netmask 255.255.255.0  設置網卡
ifconfig eth0:1 192.168.1.10 netmask 255.255.255.0  eth0:1為設置虛擬網卡

 mac地址,全球唯一,由網絡設備制造商生產時寫入網卡內部。mac地址長度為48位的十六進制數,用冒號分割 c8:5b:76:25:af:01,前六為為網卡制造商編號,后六位為系列號。要更改mac地址,需要先禁用該網卡,然后使用ifconfig

ifconfig 網卡名 down禁用網卡
ifconfig 網卡名 hw ether c8:5b:76:25:af:01修改網卡
ifconfig 網卡名 up啟用網卡

永久修改網卡配置文件要去/etc/sysconfig/network-scripts/ifcfg-eth0, 然后重啟網絡服務network

ip addr命令看到的是啥??

 

此外還有圖形配置方法!(菜單; system-config-network命令; system-config-network-tui命令)




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM