redhat 网络配置

来源:互联网 发布:广告喷绘制作软件 编辑:程序博客网 时间:2024/06/04 18:00

#一:配置文件说明。


[root@redhatlinux9 root]# cat /etc/sysconfig/network
# CAT用来显示此文件 /etc/sysconfig/network ,此文件包含了主机的最基本网络信息,用于系统启动。
NETWORKING=yes
HOSTNAME=redhatlinux9
GATEWAY=192.168.1.1
# 比如以上显示了主机名和网关信息等。

[root@redhatlinux9 root]# vi /etc/sysconfig/networ
# 可以使用VI或者图形化界面来修改,其它配置文件也是一样。


[root@redhatlinux9 root]# cat /etc/sysconfig/network-scripts/
cat: /etc/sysconfig/network-scripts/: 是一个目录
# 此 目录 下包含系统启动时用来初始化网络的一些信息。
[root@redhatlinux9 root]# cd /etc/sysconfig/network-scripts/
# 进入此目录。
[root@redhatlinux9 network-scripts]# dir
# 可以看到很多文件。
ifcfg-eth0      ifdown-isdn  ifup-aliases  ifup-plusb   ifup-wireless
ifcfg-lo        ifdown-post  ifup-ippp     ifup-post    init.ipv6-global
ifdown          ifdown-ppp   ifup-ipv6     ifup-ppp     network-functions
ifdown-aliases  ifdown-sit   ifup-ipx      ifup-routes  network-functions-ipv6
ifdown-ippp     ifdown-sl    ifup-isdn     ifup-sit
ifdown-ipv6     ifup         ifup-plip     ifup-sl
[root@redhatlinux9 network-scripts]# cat ifcfg-eth0
# 如第一块以太网卡的文件为 ifcfg-eth0,用CAT命令显示可以看到:
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.216
NETMASK=255.255.255.0
GATEWAY=192.168.1.254
# 设备名、随启动运行、静态IP地址、IP地址为192.168.1.216、掩码255.255.255.0、网关192.168.1.254

[root@redhatlinux9 etc]# cat /etc/resolv.conf
# DNS客户端配置文件,此文件用于指定域名服务器地址。
nameserver 61.134.1.9
# 这里显示到此主机的DNS服务器地址为 61.134.1.9

#------基本上配置到这里,主机已经能够完成大部分网络连接任务了,诸如连接到INTERNET。------


[root@redhatlinux9 network-scripts]# cat /etc/hosts
# 主机名映射为IP地址的文件HOSTS。
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1       redhatlinux9    localhost.localdomain   localhost


[root@redhatlinux9 etc]# cat /etc/protocols
# 此文件设定了主机使用的协议一击各个协议的协议号。
# 内容计较长,可自行查看实验,这里就不列出了。


[root@redhatlinux9 etc]# cat /etc/services
# 此文件设定了主机的不同端口网络服务。
# 内容计较长,可自行查看实验,这里就不列出了。

#------以上三个文件很少需要配置,另外还有/etc下的 networks(域名与网络ID映射文件、host.conf等。


#########################################################################################
#二:网络配置工具。

#可以使用图形化配置程序,以下我们主要看一下命令行下的配置举例:

# ifconfig

[root@redhatlinux9 /]# ifconfig
# 用来检查网络配置。
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:13627 errors:0 dropped:0 overruns:0 frame:0
          TX packets:13627 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:929096 (907.3 Kb)  TX bytes:929096 (907.3 Kb)
# 本例中主机仅存在一个回环接口。
 
[root@redhatlinux9 /]# ifconfig eth0 192.168.1.216 netmask 255.255.255.0 up
# 设置本机第一块以太网接口的地址和掩码,最后的UP代表激活此设备。

[root@redhatlinux9 /]# ifconfig eth0 192.168.1.216
# 如果设备已经激活,可以直接设置地址。

[root@redhatlinux9 /]# ifconfig eth0 down
# DOWN命令用于关闭某个网络接口。

[root@redhatlinux9 /]# ifconfig eth0 up
# UP命令用来开启某个网络接口。

[root@redhatlinux9 /]# ifconfig eth0
# 可以查看指定的网络接口。
eth0      Link encap:Ethernet  HWaddr 00:0C:29:92:FB:33
          inet addr:192.168.1.216  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:398 errors:0 dropped:0 overruns:0 frame:0
          TX packets:59 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:30699 (29.9 Kb)  TX bytes:9361 (9.1 Kb)
          Interrupt:10 Base address:0x1080


# route

[root@redhatlinux9 /]# route add default gw 192.168.1.254
# 添加缺省默认路由,主机接入互联网必需使用。

[root@redhatlinux9 /]# route add -host 192.168.1.1 dev eth0
# 添加到主机路由的方法,此处使用本地ETH0接口,视情况需要而添加。
[root@redhatlinux9 /]# route add -host 10.20.30.40 gw 192.168.1.254
# 添加到主机路由的方法,此时使用网关192.168.1.254,识情况需要而添加。

[root@redhatlinux9 /]# route add -net 192.168.0.0 netmask 255.255.255.0 eth0
# 添加到网络路由的方法,此处使用本地ETH0接口,可视情况需要而添加。
[root@redhatlinux9 /]# route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.1.254
# 添加到网络路由的方法,此处使用网关192.168.1.254,可视情况需要而添加。
[root@redhatlinux9 /]# route add -net 192.168.0.0/24 eth0
# 另一种到网络路由,掩码简写而已。

route del
# ROUTE DEL 命令用于删除路由。如route del -net 192.168.0.0 netmask 255.255.255.0 eth0
# 也就是route del 前面添加时写的语句。

route
# 显示本机路由表。


# ping

[root@redhatlinux9 /]# ping 192.168.1.216
PING 192.168.1.216 (192.168.1.216) 56(84) bytes of data.
64 bytes from 192.168.1.216: icmp_seq=1 ttl=64 time=0.094 ms
64 bytes from 192.168.1.216: icmp_seq=2 ttl=64 time=0.065 ms
 
--- 192.168.1.216 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.065/0.079/0.094/0.017 ms


# traceroute
# 追踪路由


# netstat

[root@redhatlinux9 /]# netstat -i
# 显示网络接口状态信息。

[root@redhatlinux9 /]# netstat -lpe
# 显示所由监控中的服务器的Socket和正在使用中的Socket的程序信息。

[root@redhatlinux9 /]# netstat -r
# 显示内核路由表信息。

[root@redhatlinux9 /]# netstat -nr
# 以纯地址形式显示内核路由表信息。

[root@redhatlinux9 /]# netstat -t
# 显示TCP传输协议的连接状态。

[root@redhatlinux9 /]# netstat -u
# 显示UDP协议的连接状态。


# hostname

[root@redhatlinux9 /]# hostname redhatlinux9
# 更改主机名。
[root@redhatlinux9 /]# hostname
# 显示主机名。


# arp

[root@redhatlinux9 /]# arp
# 查看ARP缓存

[root@redhatlinux9 /]# arp -s 192.168.1.13 00:50:ba:68:84:c3
# 添加一个静态绑定IP地址到MAC地址,可防止MAC地址盗用。

[root@redhatlinux9 /]# arp -d 192.168.1.13
# 删除一个对应缓存记录。

 

如何在LINUX下配置ADSL

login as: root
root@192.168.1.234's password:
Last login: Fri Jun  8 21:53:49 2007 from 192.168.1.134

[root@redhatlinux9 root]# rpm -qa|grep pppoe
rp-pppoe-3.5-2
(检查PPPOE支持的安装状况)

[root@redhatlinux9 root]# adsl-setup
(adsl-setup命令用于设置ADSL连接)

Welcome to the ADSL client setup.  First, I will run some checks on
your system to make sure the PPPoE client is installed properly...


LOGIN NAME

Enter your Login Name (default root): v88243020(账号输入)

INTERFACE

Enter the Ethernet interface connected to the ADSL modem
For Solaris, this is likely to be something like /dev/hme0.
For Linux, it will be ethX, where 'X' is a number.
(default eth0):(此处默认为eth0连接ADSL Modem,若更改可以设置选择)

Do you want the link to come up on demand, or stay up continuously?
If you want it to come up on demand, enter the idle time in seconds
after which the link should be dropped.  If you want the link to
stay up permanently, enter 'no' (two letters, lower-case.)
NOTE: Demand-activated links do not interact well with dynamic IP
addresses.  You may have some problems with demand-activated links.
Enter the demand value (default no): 5(断线重拨,默认为否,这里选择了5秒)

DNS

Please enter the IP address of your ISP's primary DNS server.
If your ISP claims that 'the server will provide dynamic DNS addresses',
enter 'server' (all lower-case) here.
If you just press enter, I will assume you know what you are
doing and not modify your DNS setup.
Enter the DNS information here: 218.30.19.40(输入DNS地址)
Please enter the IP address of your ISP's secondary DNS server.
If you just press enter, I will assume there is only one DNS server.
Enter the secondary DNS server address here: 61.134.1.4(输入辅助DNS)

PASSWORD

Please enter your Password:(输入密码)
Please re-enter your Password:(重复密码)

USERCTRL

Please enter 'yes' (two letters, lower-case.) if you want to allow
normal user to start or stop DSL connection (default yes): no(是否允许用户控制,默认为是,这里我设置为否)

FIREWALLING

Please choose the firewall rules to use.  Note that these rules are
very basic.  You are strongly encouraged to use a more sophisticated
firewall setup; however, these will provide basic security.  If you
are running any servers on your machine, you must choose 'NONE' and
set up firewalling yourself.  Otherwise, the firewall rules will deny
access to all standard servers like Web, e-mail, ftp, etc.  If you
are using SSH, the rules will block outgoing SSH connections which
allocate a privileged source port.

The firewall choices are:
0 - NONE: This script will not set any firewall rules.  You are responsible
          for ensuring the security of your machine.  You are STRONGLY
          recommended to use some kind of firewall rules.
1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation
2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway
                for a LAN
Choose a type of firewall (0-2): 2(选择NAT和防火墙,我选择了2即地址欺骗,其实可以选择0即用户自己配制防火墙,事实证明1或2自带的规则并不是很合理)

Start this connection at boot time

Do you want to start this connection at boot time?
Please enter no or yes (default no):yes(是否开机及连接,默认为否,这里我设置了是)

** Summary of what you entered **

Ethernet Interface: eth0
User name:          v88243020
Activate-on-demand: Yes; idle timeout = 5 seconds
Primary DNS:        218.30.19.40
Secondary DNS:      61.134.1.4
Firewalling:        MASQUERADE
User Control:       no
Accept these settings and adjust configuration files (y/n)? y(确认配制)
Adjusting /etc/sysconfig/network-scripts/ifcfg-ppp0
Adjusting /etc/resolv.conf
  (But first backing it up to /etc/resolv.conf.bak)
Adjusting /etc/ppp/chap-secrets and /etc/ppp/pap-secrets
  (But first backing it up to /etc/ppp/chap-secrets.bak)
  (But first backing it up to /etc/ppp/pap-secrets.bak)

 

Congratulations, it should be all set up!

Type '/sbin/ifup ppp0' to bring up your xDSL link and '/sbin/ifdown ppp0'
to bring it down.
Type '/sbin/adsl-status /etc/sysconfig/network-scripts/ifcfg-ppp0'
to see the link status.

[root@redhatlinux9 root]#

-------------------------------------------------------------------

[root@redhatlinux9 root]# adsl-
adsl-connect  adsl-setup    adsl-start    adsl-status   adsl-stop

adsl-start命令用于连接

adsl-stop用于断开

adsl-status /etc/sysconfig/network-scripts/ifcfg-ppp0用于检查连接状态

原创粉丝点击