您的位置:首页 > 理论基础 > 计算机网络

Linux 网络配置

2011-10-18 00:06 190 查看
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下网络配置就简单的介绍到这里了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: