Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5226940
  • 博文数量: 1696
  • 博客积分: 10870
  • 博客等级: 上将
  • 技术积分: 18357
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-30 15:16
文章分类
文章存档

2017年(1)

2016年(1)

2015年(1)

2013年(1)

2012年(43)

2011年(17)

2010年(828)

2009年(568)

2008年(185)

2007年(51)

分类: LINUX

2008-10-06 13:17:15

RedHat下:
1.入目
[root@Linuxsir root]# cd /etc/sysconfig/network-scripts/
2ifcfg-eh0:0中的eh0:0是网卡的代号,当然您也能eh0:1的,随您喜怎么弄,但在eh0:X之前必ifcfg,也就是下面种形式的,我eh0:0例。
[root@Linuxsir root]#cp ifcfg-eth0 ifcfg-eth0:0
3,编辑ifcfg-eth0:0
[root@Linuxsir root]# vi ifcfg-eth0:0
ifcfg-eth0:0
里面有这样的内容,您能够这样配置,然后IP自己配置了。象我这样配置也相同。
# Please read /usr/share/doc/initscripts-*/sysconfig.txt
# for the documentation of these parameters.
USERCTL='no'
NETMASK='255.255.255.0' -
》子掩
BOOTPROTO='static' -
协议
DEVICE='eth0:0' -
》虚网卡的代号
IPADDR='192.168.0.9' -
》我自己定的IP
TYPE='Ethernet' -
》是否开机激活
NETWORK='192.168.0.0' -
》网域
BROADCAST='192.168.0.255' -
》广播
4.保存退出,然后运行如下的命令,来激活虚的网卡。
[root@Linuxsir root]# ifup eh0:0
5.看我的网卡是不是激活了,用ifconfig,也就是下面这样的。
[root@Linuxsir network-scripts]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:E0:4C:00:C9:05
inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3 errors:0 dropped:0 overruns:0 frame:0
TX packets:54 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:180 (180.0 b) TX bytes:7157 (6.9 Kb)
Interrupt:11 Base address:0x2000
eth0:0 Link encap:Ethernet HWaddr 00:E0:4C:00:C9:05
inet addr:192.168.0.9 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:11 Base address:0x2000
lo Link encapocal Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:846 (846.0 b) TX bytes:846 (846.0 b)
6.ping一下IP,就能知道我做的是不是成功了。
[root@Linuxsir network-scripts]# ping 192.168.0.9
PING 192.168.0.9 (192.168.0.9) from 192.168.0.9 : 56(84) bytes of data.
64 bytes from 192.168.0.9: icmp_seq=1 ttl=255 time=0.097 ms
64 bytes from 192.168.0.9: icmp_seq=2 ttl=255 time=0.043 ms
64 bytes from 192.168.0.9: icmp_seq=3 ttl=255 time=0.043 ms
64 bytes from 192.168.0.9: icmp_seq=4 ttl=255 time=0.044 ms
64 bytes from 192.168.0.9: icmp_seq=5 ttl=255 time=0.043 ms
--- 192.168.0.9 ping statistics ---
14 packets transmitted, 14 received, 0% loss, time 12996ms
rtt min/avg/max/mdev = 0.039/0.046/0.097/0.016 ms
[root@Linuxsir network-scripts]# ping 192.168.0.1
PING 192.168.0.1 (192.168.0.1) from 192.168.0.1 : 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=255 time=0.069 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=255 time=0.042 ms
64 bytes from 192.168.0.1: icmp_seq=3 ttl=255 time=0.040 ms
64 bytes from 192.168.0.1: icmp_seq=4 ttl=255 time=0.042 ms
--- 192.168.0.1 ping statistics ---
7 packets transmitted, 7 received, 0% loss, time 5995ms
rtt min/avg/max/mdev = 0.040/0.046/0.069/0.009 ms
Debian
RedhatFedora不太相同,他把interface的信息写到了/etc/network/interfaces文档中了。以18例,一个网卡配双IP如下
# The primary network interface
auto eth0 eth0:0
iface eth0 inet static
address 202.118.250.18
netmask 255.255.255.0
network 202.118.250.0
broadcast 202.118.250.255
gateway 202.118.250.30
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 202.118.250.101
iface eth0:0 inet static
address 173.26.100.102
netmask 255.255.255.0
network 173.26.100.0
broadcast 173.26.100.255
gateway 173.26.100.46
--------------------------------------------------------------------------
Debian下一个网卡定多个ip的方法及 添加路由
linux /javasky 表于2008-03-22, 11:30
GNU nano 1.2.4 File: /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
# auto lo
表示开机候自lointerface
auto lo
# iface lo inet loopback
表示定lointerfaceloopback(本地# 接口)
iface lo inet loopback
#
eth0interface
auto eth0
# The primary network interface
# iface eth0 inet static
表示eth0是个具地址的interface
iface eth0 inet static
#address
表示ip地址
address 192.168.1.254
#netmask
表示子网掩
netmask 255.255.255.0
#
networknetmask来表示一个网192.168.1.254/24
network 192.168.1.0
#broadcast
表示广播地址
broadcast 192.168.1.255
#gateway
表示网关地址
gateway 192.168.1.1
# dns-* options are implemented by the resolvconf package, if installed
#DNS
器地址
dns-nameservers 202.103.0.117 202.103.24.68
# DNS
器地址一般在另外的一个文档里面配置,文档地址是 /etc/resolv.conf
Debian
下一个网卡定多个ip的方法(NetDC)
修改/etc/network/interfaces
auto eth0
iface eth0 inet static
address 172.16.3.123
netmask 255.255.255.0
network 172.16.3.0
broadcast 172.16.3.255
gateway 172.16.3.1
auto eth0:1
iface eth0:1 inet static
address 10.16.3.123
netmask 255.255.0.0
network 10.16.0.0
broadcast 10.16.255.255
修改/etc/network/ifstate
lo=lo
eth0=eth0
eth0:1=eth0:1
没有文档/etc/network/ifstate,手工建之
#/etc/init.d/networking restart
注意,eth0:0没有gateway
然后使用ifup eth0:0就能了。
不要使用/etc/init.d/network restart的方法
debian中,启用和停止接口用ifup ifdown的方法。
debian中添加一条路由,
方法一:修改/etc/network/interfaces
:
auto eth0
iface eth0 inet static
       address 172.16.3.222
       netmask 255.255.0.0
       network 172.16.0.0
       broadcast 172.16.255.255
       gateway 172.16.2.1
up route add -net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1
down route del -net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1
方法二:在/etc/network/if-up.d下建立一个简单的脚本文档,static-route$得以$符号尾,要不有个run-parts会跑出来告您一些西)脚本最简单的就好啦,如:
#!/bin/bash
route add -net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1
嘿嘿,您也能猜到/etc/network/下的其他目的作用了吧。
发觉debianroute的配置其只是他的那些配置文档的一个比较简单用而已,您完万能做更复

阅读(1281) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~