CentOS5取得 kernel source

Monday, September 29, 2008

Posted by Michael.Ding at 8:52 PM 0 comments

CentOS 5 上安装crond服务

Monday, September 22, 2008

最小安装的CentOS5上安装crond服务

# yum install crontabs(Root crontab files used to schedule the execution of programs.)
# yum install vixie-cron(The Vixie cron daemon for executing specified programs at set times.)

linux下的定时执行工具crontab(转贴自百度)
reference:http://hi.baidu.com/monobao/blog/item/01e9ecdcbc6a14a1cc11665b.html
cron是一个linux下的定时执行工具,可以在无需人工干预的情况下运行作业。由于Cron 是Linux的内置服务,但它不自动起linux 定时 crontab可以用以下的方法启动、关闭这个服务:

  /sbin/service crond start //启动服务

  /sbin/service crond stop //关闭服务

  /sbin/service crond restart //重启服务

  /sbin/service crond reload //重新载入配置

  你也可以将这个服务在系统启动的时候自动启动:

  在/etc/rc.d/rc.local这个脚本的末尾加上:

  /sbin/service crond start

  现在Cron这个服务已经在进程里面了,我们就可以用这个服务了,Cron服务提供以下几种接口供大家使用:

  1.直接用crontab命令编辑

  cron服务提供crontab命令来设定cron服务的,以下是这个命令的一些参数与说明:

  crontab -u //设定某个用户的cron服务,一般root用户在执行这个命令的时候需要此参数

  crontab -l //列出某个用户cron服务的详细内容

  crontab -r //删除没个用户的cron服务

  crontab -e //编辑某个用户的cron服务

  比如说root查看自己的cron设置:crontab -u root -l

  再例如,root想删除fred的cron设置:crontab -u fred -r

  在编辑cron服务时,编辑的内容有一些格式和约定,输入:crontab -u root -e

  进入vi编辑模式,编辑的内容一定要符合下面的格式:*/1 * * * * ls >> /tmp/ls.txt
这个格式的前一部分是对时间的设定,后面一部分是要执行的命令,如果要执行的命令太多,可以把这些命令写到一个脚本里面,然后在这里直接调用这个脚本就可以了,调用的时候记得写出命令的完整路径。时间的设定我们有一定的约定,前面五个*号代表五个数字,数字的取值范围和含义如下:

  分钟 (0-59)

  小时 (0-23)

  日期 (1-31)

  月份 (1-12)

  星期 (0-6)//0代表星期天

  除了数字还有几个个特殊的符号就是"*"、"/"和"-"、",",*代表所有的取值范围内的数字,"/"代表每的意思,"*/5"表示每5个单位,"-"代表从某个数字到某个数字,","分开几个离散的数字。以下举几个例子说明问题:

  每天早上6点

  0 6 * * * echo "Good morning." >> /tmp/test.txt //注意单纯echo,从屏幕上看不到任何输出,因为cron把任何输出都email到root的信箱了。

  每两个小时

  0 */2 * * * echo "Have a break now." >> /tmp/test.txt

  晚上11点到早上8点之间每两个小时,早上八点

  0 23-7/2,8 * * * echo "Have a good dream:)" >> /tmp/test.txt

  每个月的4号和每个礼拜的礼拜一到礼拜三的早上11点

  0 11 4 * 1-3 command line

  1月1日早上4点

  0 4 1 1 * command line

  每次编辑完某个用户的cron设置后,cron自动在/var/spool/cron下生成一个与此用户同名的文件,此用户的cron信息都记录在这个文件中,这个文件是不可以直接编辑的,只可以用crontab -e 来编辑。cron启动后每过一份钟读一次这个文件,检查是否要执行里面的命令。因此此文件修改后不需要重新启动cron服务。

  2.编辑/etc/crontab 文件配置cron

  cron服务每分钟不仅要读一次/var/spool/cron内的所有文件,还需要读一次/etc/crontab,因此我们配置这个文件也能运用cron服务做一些事情。用crontab配置是针对某个用户的,而编辑/etc/crontab是针对系统的任务。此文件的文件格式是:

  SHELL=/bin/bash

  PATH=/sbin:/bin:/usr/sbin:/usr/bin

  MAILTO=root //如果出现错误,或者有数据输出,数据作为邮件发给这个帐号

  HOME=/ //使用者运行的路径,这里是根目录

  # run-parts

  01 * * * * root run-parts /etc/cron.hourly //每小时执行/etc/cron.hourly内的脚本

  02 4 * * * root run-parts /etc/cron.daily //每天执行/etc/cron.daily内的脚本

  22 4 * * 0 root run-parts /etc/cron.weekly //每星期执行/etc/cron.weekly内的脚本

  42 4 1 * * root run-parts /etc/cron.monthly //每月去执行/etc/cron.monthly内的脚本

  大家注意"run-parts"这个参数了,如果去掉这个参数的话,后面就可以写要运行的某个脚本名,而不是文件夹名了。

Posted by Michael.Ding at 12:38 PM 0 comments

CentOS 5设置NTP服务器

其实非常简单,因为在CentOS 5不再区分客户端和服务器,只要配置了NTP,它就会提供NTP服务。这一点与Solaris不同,其中提供了ntp.client和ntp.server可供选择,想使用哪个直接用相应文件覆盖/etc/ntp.conf即可。

1)确认已经ntp程序包:
# yum install ntp

2)配置时间源
# vi /etc/ntp.conf
server time.lib.tsinghua.edu.cn
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org

3)配置是否为其他PC提供时间服务
# vi /etc/ntp.conf
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

4)配置开机时自动运行时间服务
# chkconfig ntpd on

5)启动或停止时间服务
# service ntpd start
# service ntpd stop
# service ntpd restart

6)验证ntp服务已经运行
# pgrep ntpd

7)初始同步
# ntpdate -u time.lib.tsinghua.edu.cn

8)确认同步成功
# ntpq -p

当然,如果要提供时间服务,还必须相应的设置iptable防火墙的配置。CentOS的时间服务使用udp 123端口。

Posted by Michael.Ding at 11:34 AM 0 comments

iptables+squid透明代理

squid 2.6 简单配置
=========================
cat squid.conf|sed '/^\#/d'|sed '/^$/d'或者grep -v -E '^$|^#' squid.conf

acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access allow all
icp_access allow all
http_port 3128 transparent
hierarchy_stoplist cgi-bin ?
cache_mem 96 MB
cache_dir ufs /var/spool/squid 100 16 256
access_log /var/log/squid/access.log squid
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
cache_mgr tech@xintv.com
visible_hostname CentOS5
error_directory /usr/share/squid/errors/Simplify_Chinese
coredump_dir /var/spool/squid

==============================
iptables 命令

如果防火墙和代理服务器在一起
eth0:内网IP eth1:外网IP
iptables -t nat -A PREROUTING -s 172.168.100.0/24 -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128

如果不在一起,代理服务器:172.168.100.191
iptables -t nat -A PREROUTING -s 172.168.100.0/24 -i eth0 -p tcp -m tcp --dport 80 -j DNAT --to 172.168.100.191:3128
iptables -t nat -A POSTROUTING -o eth0 -s 172.168.100.0/24 -d 172.168.100.191 -j SNAT --to 172.168.100.201

===========================
iptables 的一些管理
acl badsite url_regex -i taobao.com
http_access deny badsite
限制访问特定的网站
acl numconn maxconn 2
http_access deny all numconn
限制访问每个IP的链接数(注意:client_db要设为on)

===========================
开启ip_forward转发
只修改当前环境的转发
echo 1 > /proc/sys/net/ipv4/ip_forward
永久修改环境的转发
vi /etc/sysctl.conf
修改
net.ipv4.ip_forward = 0

net.ipv4.ip_forward = 1

直接vi编辑/proc/sys/net/ipv4/ip_forward是会报错的,因为/proc里面是虚拟档案系统目录,都是在ram上。里面的文档通过重导或者修改sysctl.conf达到修改的目的。通过重导重启以后,或者重启网卡后就恢复原状了。

reference for iptables
http://iptables-tutorial.frozentux.net/cn/iptables-tutorial-cn-1.1.19.html
http://bbs.chinaunix.net/viewthread.php?tid=477137
http://bbs.chinaunix.net/viewthread.php?tid=281136
http://blog.platinum.net.cn/index.php?op=ViewArticle&articleId=59&blogId=1
http://bbs.chinaunix.net/viewthread.php?tid=536582&extra=&page=1
http://www.chinaunix.net/jh/4/293819.html
http://bbs.chinaunix.net/viewthread.php?tid=559519
http://bbs.chinaunix.net/viewthread.php?tid=602090
http://www.linuxaid.com.cn/engineer/ideal/article/policy_pouting.htm
http://bbs.chinaunix.net/viewthread.php?tid=304033
http://chinaunix.net/jh/38/505206.html
http://www.vbird.org/linux_server/0420squid.php

========================
ipp2p模块
http://linux.chinaunix.net/bbs/viewthread.php?tid=914377

========================
命令补充
# lsmod
lsmod(list modules)

功能说明:显示已载入系统的模块。

语  法:lsmod

补充说明:执行lsmod指令,会列出所有已载入系统的模块。Linux操作系统的核心具有模块化的特性,应此在编译核心时,务须把全部的功能都放入核心。您可以将这些功能编译成一个个单独的模块,待需要时再分别载入。

# modinfo
modinfo(module infomation)

功能说明:显示kernel模块的信息。

语  法:modinfo [-adhpV][模块文件]

补充说明:modinfo会显示kernel模块的对象文件,以显示该模块的相关信息。

参  数:
-a或--author  显示模块开发人员。
-d或--description  显示模块的说明。
-h或--help  显示modinfo的参数使用方法。
-p或--parameters  显示模块所支持的参数。
-V或--version  显示版本信息。

# modprobe
modprobe(module probe)

功能说明:自动处理可载入模块。

语  法:modprobe [-acdlrtvV][--help][模块文件][符号名称 = 符号值]

补充说明:modprobe可载入指定的个别模块,或是载入一组相依的模块。modprobe会根据depmod所产生的相依关系,决定要载入哪些模块。若在载入过程中发生错误,在modprobe会卸载整组的模块。

参  数:
-a或--all  载入全部的模块。
-c或--show-conf  显示所有模块的设置信息。
-d或--debug  使用排错模式。
-l或--list  显示可用的模块。
-r或--remove  模块闲置不用时,即自动卸载模块。
-t或--type  指定模块类型。
-v或--verbose  执行时显示详细的信息。
-V或--version  显示版本信息。
-help  显示帮助。

Posted by Michael.Ding at 10:46 AM 0 comments

ROUTEOS使用笔记

ROUTEOS使用笔记
宽带和ADSL(PPPoE)不一样。
宽带:单击IP,DHCP Clients,Enable,Add Default Route,Interface 选择ether2,hostname为Client1,OK。再次打开DHCP Clients,查

看Status页看是否获取IP地址,如果获取了就完工了。
ADSL拨号设置如下:
在WINBOX中,点interfaces-->增加(+)-->pppoe clients-->dial out
在user框输入adsl拨号用户名,在password框输入密码,并对选项框打勾(保存ADSL密码)-->APPLY.
------------------------------------------------------------------------------------------
设置NAT共享上网ip --》firewall -source nat ,选择 + 号,选择action,action里面选择 masquerade

/ip firewall mangle add protocol tcp tcp-options syn-only tcp-mss 1448
------------------------------------------------------------------------
开DHCP
添加ip pool地址池
再开 ip dhcp server设上网关和dns
---------------------------------------------------------------------------
用RouterOS封PP点点通和VPP

因为本网吧经常有人利用PP点点通和VPP下载黄色电影,不但影响不好,而且很占
网络资源,降底网速,其它玩游戏者老是叫卡.所以作了以下处理:

用WINBOX登录,在IP-->Firewall的forward处添加:
第一条规则:
General页中的Dst.address改为210.15.29.67/32
Action页中的Action改为drop或reject
第二条规则:
General页中的Dst.address改为210.15.29.68/32
Action页中的Action改为drop或reject
第三条规则:
Advanced页中的content改为pp365
Action页中的Action改为drop或reject

这样设置后,别人登录PP点点能或VPP时就会提示说网络不通.
不知道PP和VPP还有没有其它服务器,有的话请告诉我IP址.

装个天网防火墙,然后分别登录pp点点通和pp,登陆的时候防火墙会提示ip连接的,将ip记下来,然后写在防火墙的规则里面.

用CommView可以看连接的。我就是用它来看QQ的连接。并封掉了其IP。QQGame也玩不了了
-------------------------------------------------------------------
ROUTEROS下限IP的TCP连接数(限线程),
来自每个IP地址最多允许有15个并发连接

/ip firewall rule forward add protocol=tcp tcp-options=syn-only connection-limit=15 \
action=drop

專門限制一個IP的連接數
/ip firewall rule forward add protocol=tcp tcp-options=syn-only
src-address=192.168.0.249/32 connection-limit=15 action=drop
--------------------------------------------------------------------------------------
如果有一些网页打不开,你ISP的MTU=1492,请在IP > Firewall > Mangle > 单击红加号 > Protocol选择TCP > Tcp Options 选择 sync >

Actions选择 accept >TCP MSS:1448。
------------------------------------------------------------------------------------------
ip -》firewall -》filter fules ,选择 + 号,in interface 选择内网网卡(local),其他默认
这条路由允许来自内网的连接,如果有限制,可以修改 src address 的ip段,或者content 内容过滤

ip -》firewall -》filter chains 选中 input ,选择 drop
这条规则禁止所有的外部连接

以上两条规则,屏蔽来自外网的所有连接

一些恶意网站和广告,也可以从这里屏蔽
例如,可以加一条规则,禁止登陆新浪聊天室:
ip -》firewall -》filter fules ,选择forward
选择+号,advanced 里面content 输上chat.sina.com ,action里面选择return,即可
如果chat.sina.com 换成ad4.sina.com.cn ,新浪主页的广告就没有了
防火墙设置需要较强的网络知识,可以参考有关资料,或者天网等防火墙里面的规则

---------------------------------------------------------------------------------------------------
如果内部有需要对外发布的服务,例如ftp、web等,可以在ip firewall 的destination nat中设置,添加是注

意:dst.address 要用你对外的ip,选择相应的协议,端口号,另外acction中选择 nat ,天上内网对应主机

ip 、端口号。
--------------------------------------------------------------------------------------------------
全面解决ROUTER OS IP 限速问题

比如我要限:172.18.62.63的下载为:上限100Kbit-下限256Kbit,上行为:上限100Kbit-200Kbit下限,具体可以这样做:


1、下载带宽 IP---Simple Queues---"+"
Name=down SrcAddress=0.0.0.0/0 DstAddress=192.168.0.8/32 terface=eth1(内网网卡) limit at=100000 Maxlimit=256000
2、上传带宽 IP---Firewall---Mangle---"+"
SrcAddress=192.168.0.8/32 InInterface=eth1(内网网卡)DstAddress=0.0.0.0/0 Protocol=all Action=accept FlowMark=UP
3.Queues---QueuesTree---"+"
Name=UP Parent=eth2(外网网卡) Flow=UP limit=100000MaxLimit=200000

你要限多少个IP,就写多少个。我写了近:300来个IP,上行下行没有问题。
我这里是250台这样的网络,才4M的带宽,随时保持60-100来户人同时在线。ROUTER OS运行了4天4夜,PING 值一般小于:10MS,没有发现丢包现像

,速度用户反馈速度很快,不过我的防火墙设了一些规则,朋友们如果感兴趣,自己编些规则,与天网差不多,如果不熟TCP/IP的朋友,买一本回

来,不出1个月,你就精通了。
在Queues---QueuesTree里面还可以看在线用户当前速率。
方便无比。你要限谁就限谁。
我这里有6万个IP,我只开放172.18.60.0-172.18.60.127;172.18.61.0-172.18.61.127;
172.18.62.0-172.18.62.63

所以限了近:300来个IP。还可以限一个网段如:172.18.60.0/25
限制一个网段用PCQ

1. Mark all packets with flow all:用flow all 标记所有数据包
/ip firewall mangle add action=accept mark-flow=all

2. Create two PCQ queue types - one for download and one for upload. For download traffic:创建两条PCQ类型,下载和上传
queues will be classified by dst-address and for upload - by src-address:
/queue type add name=PCQ-Download kind=pcq pcq-rate=65536 \
pcq-classifier=dst-address
/queue type add name=PCQ-Upload kind=pcq pcq-rate=32768 \
pcq-classifier=src-address

3. Add two queue rules - one for download and one for upload:添加PCQ规则,下载和上传/
queue tree add parent=Local queue=PCQ-Download flow=all
/queue tree add parent=Public queue=PCQ-Upload flow=all
-----------------------------------------------------------------------------------------------
关于解决不能上百度的问题
把TCP MSS 1448改成1432
----------------------------------------------------------------------------------------------------
这是官方的在线模拟
http://demo.mt.lv/
下载 MikroTik WinBox Console
我们做好的管理登陆界面也是这样的,
打开winbox
在Connect To填 demo.mt.lv
用户名Login填 demo
密码留空
然后点connect连接
---------------------------------------------------------------------------------------------------------------
RouterOS的端口映射很简单.
在终端中的ip/firewall/dst-nat里面
比如我要映射80端口到192.168.0.100,外网地址是218.26.x.x(假设)
输入add action=nat protocol=tcp dst-address=218.26.x.x/32:80 to-dst-address=192.168.0.100
就ok了,需要注意的是做nat的时候,dst-address的子网掩码必须是32,也就是255.255.255.255,否则不行,很多朋友出问题就是出在这里.
----------------------------------------------------------------------------------------------------------
记录网卡MAC地址才能限制网卡上网。具体设置如下。
在防火墙里面的filter rules项选择forward然后添加一项设定也就是“+”号,
在advanced项里面的src .mac.address项里面加入网卡的MAC地址,然后在ACTION中选择DROP项。这样子添加后,那块网卡的ip地址无论咋换,都

无法上网。除非它把网卡换了。我就是这样子作出来得,效果不错。
-----------------------------------------------------------------------------------------
[admin@MikroTik] system backup>save导出配置文件,就是备份
[admin@MikroTik] system backup>load导入配置文件,就是恢复
-----------------------------------------------------------------------
如果改了端口用winbox打不开了的解决方法
用SSH进入

/ip ser

/ip ser/>set www port 80

/ip ser/>set ftp port 21
-------------------------------------------------------
官方防火墙设置如下:

/ ip firewall
set input name="input" policy=accept comment=""
set forward name="forward" policy=accept comment=""
set output name="output" policy=accept comment=""
add name="virus" policy=none comment=""
/ ip firewall rule forward
add connection-state=invalid action=drop comment="Drop invalid \
connections" disabled=no
add connection-state=established action=accept comment="Established \
connections" disabled=no
add connection-state=related action=accept comment="Related connections" \
disabled=no
add action=jump jump-target=virus comment="!!! Check for well-known \
viruses !!!" disabled=no
add protocol=udp action=accept comment="UDP" disabled=no
add protocol=icmp limit-count=50 limit-burst=2 limit-time=5s \
action=accept comment="Allow limited pings" disabled=no
add protocol=icmp action=drop comment="Drop excess pings" disabled=no
/ ip firewall rule input
add connection-state=invalid action=drop comment="Drop invalid \
connections" disabled=no
add tcp-options=non-syn-only connection-state=established action=accept \
comment="Accept established connections" disabled=no
add connection-state=related action=accept comment="Accept related \
connections" disabled=no
add action=jump jump-target=virus comment="!!! Check for well-known \
viruses !!!" disabled=no
add protocol=udp action=accept comment="UDP" disabled=no
add protocol=icmp limit-count=50 limit-burst=2 limit-time=5s \
action=accept comment="Allow limited pings" disabled=no
add protocol=icmp action=drop comment="Drop excess pings" disabled=no
add dst-address=:22 protocol=tcp action=accept comment="SSH for demo \
purposes" disabled=no
add dst-address=:23 protocol=tcp action=accept comment="Telnet for demo \
purposes" disabled=no
add dst-address=:80 protocol=tcp action=accept comment="http for demo \
purposes" disabled=no
add dst-address=:3987 protocol=tcp action=accept comment="winbox for \
demo purposes" disabled=no
add src-address=159.148.172.192/28 action=accept comment="From \
Mikrotikls network" disabled=no
add src-address=10.0.0.0/8 action=accept comment="From Mikrotikls \
network" disabled=no
add action=drop log=yes comment="Log and drop everything else" \
disabled=no
/ ip firewall rule output
add protocol=tcp tcp-options=syn-only action=drop log=yes comment="" \
disabled=no
/ ip firewall rule virus
add dst-address=:134-139 protocol=tcp action=drop comment="Drop Blaster \
Worm" disabled=no
add dst-address=:134-139 protocol=udp action=drop comment="Drop \
Messenger Worm" disabled=no
add dst-address=:445 protocol=tcp action=drop comment="Drop Blaster \
Worm" disabled=no
add dst-address=:445 protocol=udp action=drop comment="Drop Blaster \
Worm" disabled=no
add dst-address=:593 protocol=tcp action=drop comment="________" \
disabled=no
add dst-address=:1024-1030 protocol=tcp action=drop comment="________" \
disabled=no
add dst-address=:1080 protocol=tcp action=drop comment="Drop MyDoom" \
disabled=no
add dst-address=:1214 protocol=tcp action=drop comment="________" \
disabled=no
add dst-address=:1363 protocol=tcp action=drop comment="ndm requester" \
disabled=no
add dst-address=:1364 protocol=tcp action=drop comment="ndm server" \
disabled=no
add dst-address=:1368 protocol=tcp action=drop comment="screen cast" \
disabled=no
add dst-address=:1373 protocol=tcp action=drop comment="hromgrafx" \
disabled=no
add dst-address=:1377 protocol=tcp action=drop comment="cichlid" \
disabled=no
add dst-address=:1433-1434 protocol=tcp action=drop comment="Worm" \
disabled=no
add dst-address=:2745 protocol=tcp action=drop comment="Bagle Virus" \
disabled=no
add dst-address=:2283 protocol=tcp action=drop comment="Drop Dumaru.Y" \
disabled=no
add dst-address=:2535 protocol=tcp action=drop comment="Drop Beagle" \
disabled=no
add dst-address=:2745 protocol=tcp action=drop comment="Drop Beagle.C-K" \
disabled=no
add dst-address=:3127-3128 protocol=tcp action=drop comment="Drop \
MyDoom" disabled=no
add dst-address=:3410 protocol=tcp action=drop comment="Drop Backdoor \
OptixPro" disabled=no
add dst-address=:4444 protocol=tcp action=drop comment="Worm" \
disabled=no
add dst-address=:4444 protocol=udp action=drop comment="Worm" \
disabled=no
add dst-address=:5554 protocol=tcp action=drop comment="Drop Sasser" \
disabled=no
add dst-address=:8866 protocol=tcp action=drop comment="Drop Beagle.B" \
disabled=no
add dst-address=:9898 protocol=tcp action=drop comment="Drop Dabber.A-B" \
disabled=no
add dst-address=:10000 protocol=tcp action=drop comment="Drop Dumaru.Y" \
disabled=no
add dst-address=:10080 protocol=tcp action=drop comment="Drop MyDoom.B" \
disabled=no
add dst-address=:12345 protocol=tcp action=drop comment="Drop NetBus" \
disabled=no
add dst-address=:17300 protocol=tcp action=drop comment="Drop Kuang2" \
disabled=no
add dst-address=:27374 protocol=tcp action=drop comment="Drop SubSeven" \
disabled=no
add dst-address=:65506 protocol=tcp action=drop comment="Drop PhatBot, \
Agobot, Gaobot" disabled=no
------------------------------------------------------
解决因防火墙屏蔽来自内网的所有连接
进入后输入 /ip f ru o 可打开OUTPUT 输入 //ip f ru in 可打开INPUT
再、输入p 可看结果
按REM O(此0为数字)可删除相应0的规则
你输入/ip f set i p a 可恢复系统默认input改回accept。
或者,使用system 里面的reset 复位路由(会删除所有规则)
----------------------------------------------------------------------
HotSpot设置一步一步指导
首先你要安装好routeros 2.8.7以上的版本。


CODE
[admin@MikroTik] > system reset



(系统自动复位清除设置并重新启动)

让我们来看看这个机器上有哪些网卡:

CODE
[admin@MikroTik] > /interface print

Flags: X – disabled, D – Dynamic, R - Running
# NAME TYPE MTU
0 X ether1 ether 1500
1 X ether2 ether 1500


你可以看到这个机器上有两张网卡显示,但是却是禁止的。
让我们来来给网卡指定名字,让以后看起来更方便

CODE
[admin@MikroTik] interface> set 0 name=”hotspot”
[admin@MikroTik] interface> set 1 name=”internet”
[admin@MikroTik] interface> print

Flags: X – disabled, D – Dynamic, R - Running
# NAME TYPE MTU
0 R internet ether 1500
1 R hotspot ether 1500



我们能根据名字更容易的查看某一张网卡的状态,让我们来给网卡指定IP地址。
设置routeros的inernet网卡的地址为192.168.1.2,设置网关为192.168.1.1,dns用你的isp给你的。我们用212.159.13.50

CODE
[admin@MikroTik] > /ip
[admin@MikroTik] ip> address add address=192.168.1.2/24 interface=internet
[admin@MikroTik] ip> route add gateway=192.168.1.1
[admin@MikroTik] ip> dns
[admin@MikroTik] ip dns> set primary-dns=212.159.13.50
[admin@MikroTik] ip dns> set secondary-dns=212.159.11.50



启用dns缓存

CODE
[admin@MikroTik] ip dns> set allow-remote-requests=yes
[admin@MikroTik] ip dns> ..


现在设置hotspot这张网卡

CODE
[admin@MikroTik] ip> hotspot
[admin@MikroTik] ip hotspot> setup
Select interface on which to run HotSpot
Hotspot interface: hotspot
Enable universal client configuration?
Enable universal client: yes


这个功能是允许远程机器连接到即使他们使用完全不同的网络设置

CODE
Local address of hotspot network gateway: 10.5.50.1/24
Masquerade hotspot network: yes
Address pool of hotspot network will be: 10.5.50.2-10.5.50.254
ip address of smtp server: 192.168.1.3


我们必须输入你的ISP的smtp服务器的IP,如果你没有,你可以给一个“internet” 段的IP。

CODE
Use local DNS cache?
use local DNS cache: yes
Setup DNS Configuration
dns servers: 192.168.1.2



设置dns

CODE
Name of hotspot user: admin
Password for the user: admin


设置hotspot超级管理员的用户名和口令(一定要保证安全)

CODE
Select another port for (www) service
Another port for service: 8081


指定另外一个端口8081给winbox用

CODE
Use transparent web proxy for hotspot clients?
Use transparent web proxy: yes


使用web代理缓存

最后就设置好了。
-----------------------------------------------------------------------------
如何映射和回流(详细,有图)

映射
winbox----ip-----firewall-----Destination nat
+---- ⑴General 页
SRC。ADDRES |__ __ _ 默认
SRC。PORT |
INTEface all
Dst.address 外网ip /32(此32是定值)
Dst.port 映射端口(我这里是27015-27016)
⑵ ACTION 页
Action: nat
To Dst. address 192.168.1.253-192.168.1.253(内网提供服务的机器IP)
To Dst. Ports:27015-27016

回流

winbox----ip-----firewall-----Source NAT
+----- ⑴GERENAL页
Src.Address 192.168.1.253(内网提供服务器机器的IP) /32(此32是定值)
src.port
Dst.Address 192.168.1.0(你内网IP的前3位+0)/24(这里是你掩码的换算值)
Protocol 你自己的协议
⑵ Action页
action: nat
to Src.addresses 0.0.0.-0.0.0.0
TO src.ports:27015-27016
----------------------------------------------------------------------------
RouterOS整体限速
ip firewall mangle add action=accept mark-flow=all
以限制下载速度64K上行速度32K为例
/queue type add name=PCQ-Download kind=pcq pcq-rate=65536 pcq-classifier=""
/queue type add name=PCQ-Upload kind=pcq pcq-rate=32768 pcq-classifier=""
在WINBOX里PCQ-Download勾上Src.,PCQ-Upload勾上Dst.
/queue tree add parent=Local queue=PCQ-Download flow=all //Local为本地网卡
/queue tree add parent=Public queue=PCQ-Upload flow=all //Public为外网网卡

以上方法同样适用于对P2P限速。在ip firewall mangle里Advanced下p2p加上P2P-ALL就可以了。
------------------------------------------------------------------------------------
1。备份和恢复设置

绝对是好东东!你想想辛辛苦苦设置好的防火墙规则,网卡设置,各个路由,端口映射万一弄错了或重新安装时,是不是都要重新自已设置?这个

巨麻烦!!!但ROUETOS却为你考虑得很周到,可以手工备份你的设置文件,需要时只要一个命令即可恢复!

大家可以用WINBOX登陆,注意用ADMIN帐号,在左边是不是有个FILES?点开,再点对话框上面的BACKUP,这样就把当前的设置保存一个文件里面了

,再用IE登陆你的路由,用ftp://网管帐号:密码@路由IP:端口,登陆到你的路由后就会到你保存的文件了!用IE直接下载吧!

当你重新安装时,只要把内网弄通,用IE再登陆你的路由,把这个设置文件传上去,在WINBOX左边下面有个TE开头的英文,这是终端模拟,点开后

就像在路由上操作一样,用以下命令恢复你以前的设置:

system回车

backup回车

load name=你保存的设置文件名 回车

提示重启就一下子恢复到你以前设置了!!

是不是方便实用啊?

大家可能会说用WINBOX备份不爽,那我们也可以用终端备份呀!

在WINBOX左边下面有个TE开头的英文,这是终端模拟,点开后就像在路由上操作一样,用以下命令备份你以前的设置:

system回车

backup回车

save name=你保存的设置文件名 回车

建议文件名用日期表示可以很直观。这样就按你的文件名保存了。

用LOAD NAME命令就是恢复了。。。]

2.恢复路由本身默认值。

如果设错了规则或者地址,造成win不能进入管理界面,可以这样复原:
使用 admin 登陆
system 回车
reset 选择 y
将删除所有改动,恢复新装的状态

这个是恢复到出厂设置,很适合刚开始设置ROUTEOS时用用!

3。备份ROUTEOS

可以用GHOST8。0备份,注意是要用全盘备份,DISK TO IMG才行。

4。简单化输入

在ROUTEOS是不是感觉输入命令很麻烦?

其实ROUTEOS可以只要输入前两位字母就可以了。。。

比如上面的命令:

system

backup

这是进入目录的,可以简化成:

sy

ba

即可!很适合一些懒人。。。哈哈

5。检查磁盘

在路由或终端模拟下用下面命令:

system

check-disk

检查磁盘,要重启。 但是很慢,一分钟一G。。。哈哈

6。关机

可以在WINBOX中关机,也可以用命令关:

system

sh

即可

Posted by Michael.Ding at 10:22 AM 0 comments