(编辑:jimmy 日期: 2025/10/30 浏览:2)
建立一个文件夹把驱动复制到里面 
#mkdir /usr/local/src/em 
解压缩 
#tar xvfz em-5.1.5.tar.gz 
#cd em-5.1.5 
编译模块 
# make 
安装编译好的模块 
#make install 
如果你想启动的时候自动加载模块修改 
ee /boot/loader.conf 
添加if_em_load="YES" 
------------------------------------------------------ 
编译驱动到内核 
cd /usr/local/src/em/em-5.1.5/src 
cp if_em* /usr/src/sys/dev/em 
cp Makefile.kernel /usr/src/sys/modules/em/Makefile 
修改/usr/src/sys/conf/files.i386 文件添加以下两行到文件 
内
dev/em/if_em.c optional em  
dev/em/if_em_hw.c optional em  
修改你的内核配置文件。确定有 
device em
编译安装内核。。。reboot.完成
----------------------------------------------------------- 
下面说下有关网卡设置的参数 
ifconfig_em<interface_num>="<ifconfig_settings>" 
ifconfig em<interface_num> <IP_address> media 100baseTX mediaopt  full-duplex 
驱动所支持的模式:
autoselect - Enables auto-negotiation for speed and duplex.
   10baseT/UTP     -  Sets speed to 10 Mbps. Use the ifconfig mediaopt  
                      option to select full-duplex mode.
   100baseTX       -  Sets speed to 100 Mbps. Use the ifconfig mediaopt 
                      option to select full-duplex mode.
   1000baseTX      -  Sets speed to 1000 Mbps. In this case, the driver 
                      supports only full-duplex mode.
   1000baseSX      -  Sets speed to 1000 Mbps. In this case, the driver 
                      supports only full-duplex mode.
ifconfig em<interface_num> <hostname or IP address> mtu 9000 
route get <destination_IP_address>
[color=Red]VLANS设置[/color]建立vlan 
#ifconfig <vlan_name> create 
网卡的配置: 
ifconfig <vlan_name> <ip_address> netmask <subnet_mask> vlan  <vlan_id> vlandev 
<physical_interface> 
例如: 
ifconfig vlan10 10.0.0.1 netmask 255.255.255.0 vlan10 vlandev em0 
删除VLAN 
#ifconfig <vlan_name> destroy
[color=Red]Polling模式:本来网卡工作模式:需要的时候请求中断。但在拒绝服务攻击情况下,包数太多,就不太
可行,polling模式就是让cpu定期去取网卡内存中的数据包。虽然平时看上去这种方法比较效率低,但在
拒绝服务攻击情况下就比较好用。[/color] 
在内核中确保: 
options DEVICE_POLLING 
可选: 
options HZ=1000 
polling在sysctl中参数的含义 
kern.polling.enable=1           打开polling模式 
kern.polling.burst                  每个时间片,系统在每个网卡可以抓的最多的包值,不可以改的值,根据其
他值系统自己算的 
kern.polling.burst_max          每次取多少内存中的包默认150,是 一个参数,和内核里面的HZ相乘(HZ * 
burst_max)就是每秒cpu极限可以抓的包量   默认HZ=1000 
kern.polling.each_burst         没搞懂用处,默认5 好像用处不大 
kern.polling.idle_poll=1          man 中推荐打开选项 
kern.polling.reg_frac             多久检测一次网卡错误 默认20 
kern.polling.user_frac=10      cpu预留给userland  tasks的量 默认50, 做防火墙推荐少留一点 
kern.polling.handlers              有多少网卡注册了polling服务  不用改
注:HZ的含义以及burst_max的关系,HZ就是赫兹,时间的倒数,就是多久cpu去取一次网卡内存中的包 
HZ越大,CPU去取的时间间隔越短,burst_max就是每次取多少内存中的包。 
这个参数需要自行测试,HZ越大,在大流量下用top看中断就越多 
感觉范围在500-2000比较合适,再大就。。。。。 
在内核中为:options HZ=500   (我设置500,burst_max设置150,可保证我的服务器稳定和抗攻击能力比较好)