Linux 網絡配置

1. 介紹

Linux 網絡管理主要涉及到一些配置文件和一些網絡配置命令,熟悉這些文件和命令對於配置Linux網絡十分重要。

在本文中,主要介紹一下幾個重要的網絡配置文件和網絡配置命令。

2. 網絡配置文件

(1)/etc/hosts

 

[root@localhost etc]#  cat </etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6

 

 

這個文件主要包含主機名到IP地址的映射。如果沒有DNS服務器,可以通過這個進行解析。

 

(2) /etc/resolv.conf

 

[root@localhost etc]# cat <resolv.conf
search localdomain
nameserver 202.97.224.68

 

nameserver 即DNS,主要是用來配置DNS的。裏面是DNS服務器的IP地址。

 

 

(3) /etc/sysconfig/network

[root@localhost etc]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost.localdomain

 

所有的網絡接口設備路由和主機信息。

 

(4) /etc/sysconfig/network-script/ifcfg-<interface-name>

 

[root@localhost network-scripts]# cat ifcfg-eth0
# Broadcom Corporation NetLink BCM5787M Gigabit Ethernet PCI Express
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
BOOTPROTO=none
HWADDR=00:1c:c4:d0:06:c4
TYPE=Ethernet
NETMASK=255.255.255.0
IPADDR=58.155.107.233
GATEWAY=58.155.107.1
USERCTL=no
IPV6INIT=no
PEERDNS=yes

 

 

每一個網絡接口的配置信息,這裏是eth0的配置信息。

 

 

3. 網絡配置命令

 

(1)ifconfig [interface]

查看網卡信息。

如 ifconfig eth0

 

[root@localhost network-scripts]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:1C:C4:D0:06:C4 
          inet addr:58.155.107.233  Bcast:58.155.107.255  Mask:255.255.255.0
          inet6 addr: 2001:250:7801:c14:21c:c4ff:fed0:6c4/64 Scope:Global
          inet6 addr: fe80::21c:c4ff:fed0:6c4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:18760 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4838 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:13988920 (13.3 MiB)  TX bytes:1002075 (978.5 KiB)
          Interrupt:18

 

(2)配置IP地址

 

ifconfig eth0 222.27.253.108 netmsk 255.255.255.0

配置IP地址與子網掩碼。

 

ifconfig eth0 hw ether  xx:xx:xx:xx:xx:xx

配置Mac.

 

 

(3) 網卡禁用與啓用

 

ifconfig eth0 down

ifconfig eth0 up

 

通常情況下,先禁用網卡,進行配置之後纔再次啓用網卡,正常配置以後就能夠上網了。

關於Linux下網絡配置就簡單的介紹到這裏了。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章