FreeBSD 服务器设置 简明攻略

FreeBSD 服务器设置 简明攻略

作者:FreeBSD 服务器设置 简明攻略
转载请保留作者信息

葱头

近段时间越来越多朋友利用FreeBSD强大的网络功能建立自己的服务器,在这过程中可能遇到了一些麻烦.为了大家少走弯路,这里力求简单说明一些常用服务的设置.

基本网络设置:

defaultrouter="192.168.0.1"
gateway_enable="YES"
hostname="xxxhost.xxxdomain.com"
ifconfig_rl0="inet 192.168.0.1 netmask 255.255.255.0"

注意: rl0为内网卡,你需要按你实际的网卡设备去写.

一 如何在FreeBSD设置ADSL上网

我曾经发表过一篇这样的文章,在这里我不在罗嗦了. 可以参考下面:

如何在FreeBSD设置ADSL上网(在FreeBSD 4.4下测试通过)
网上有部分关于FreeBSD设置ADSL上网的文章有些错误,这里公布葱头的设置文件。
1。编辑/etc/ppp/ppp.conf 文件

default:
set log Phase tun command
enable dns

adsl:
set device PPPoE: 设备名 ;即网卡的设备名
set speed sync
set mru 1492
set mtu 1492
set dial
set login
add default HISADDR
set authname 帐户名
set authkey 密码

Papchap:
set authname 帐户名
set authkey 密码

2。编辑/boot/defaults/loader.conf
ng_pppoe_load="YES"


虚拟拨号: ppp -background adsl
测试: ifconfig -a 看到tun0伪设备捆绑了ISP分配的IP地址即成功

如果想开机就自动拨号,那就要修改/etc/rc.conf,增加一下字段:
ppp_enable="YES"
ppp_mode="ddial"
ppp_profile="adsl"



二 设置缓冲型DNS

1. 编辑/etc/resolv.conf

domain xxxxx.com
nameserver 127.0.0.1
nameserver xxx.xxx.xxx.xxx.xxx
nameserver xxx.xxx.xxx.xxx.xxx
(后面两个一般在拨号时自动生成, 那是ISP的域名解析服务器地址. 127.0.0.1必须放在他们之前)

2. 创建localhost.rev文件
chmod 744 /etc/namedb/make-localhost (将脚本改为可执行)
cd /etc/namedb
./make-localhost

3.编辑/etc/namedb/named.conf

options {
directory "/etc/namedb";
forward only;
forwarders {
xxx.xxx.xxx.xxx; xxx.xxx.xxx.xxx;
};
};

zone "." {
type hint;
file "named.root";
};

zone "0.0.127.IN-ADDR.ARPA" {
type master;
file "localhost.rev";
};

注: 上面两个xxx.xxx.xxx.xxx就是/etc/resolv.conf 里面的两个nameserver地址

4.修改/etc/rc.conf
加入 named_enable="YES"


三 设置透明代理

这里假设你已经设置好squid并已投入使用,如果大家对squid不熟悉的话,我稍后会贴出squid的设置.
一般网上都是用ipfw做防火墙的,但我觉得ipfilter较ipfw方便而且好用,所以这里采用ipfilter.

1.编辑/boot/defaults/loader.conf
在Networking modules段加入:
ipl_load="YES"

2.创建/etc/ipfilter.rules (ipfilter规则),这里仅仅给出一个例子,要根据自己的实际需求设定规则.

block in log on 外网卡名 from any to any
block out log on 外网卡名 from any to any
pass out log on 外网卡名 proto icmp all keep state
pass out log on 外网卡名 proto tcp/udp from any to any keep state
pass in on 外网卡名 proto tcp from any to any port = ftp-data keep state
pass in on 外网卡名 proto tcp from any port = ftp-data to any port > 1023 keep state
pass in on 内网卡名 all
pass out on 内网卡名 all
block return-rst in log on 外网卡名 proto tcp from any to any flags S/SA
block return-icmp(net-unr) in log on 外网卡名 proto udp from any to any

3.创建/etc/ipnat.rules (NAT规则)
rdr 内网卡名 0.0.0.0/0 port 80 -> 192.168.0.1 port 3128 tcp/udp

注: 192.168.0.1 为内网卡ip地址, 并假设你的squid的端口为3128,不是的话改成实际的就可以了.


4.编辑 /etc/rc.conf , 加入:

ipfilter_enable="YES"
ipfilter_rules="/etc/ipfilter.rules"
ipnat_enable="YES"
ipnat_rules="/etc/ipnat.rules"

到这里为止,整个设置透明代理设置基本完成, 确保你的squid服务正常并开机自动启动. 然后重新启动服务器.将客户端电脑的网关和DNS服务器地址都改为内网卡ip地址(我那里是192.168.0.1) 就可以了.



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The critically-acclaimed FreeBSD guide, now expanded, revised, and updated! FreeBSD is the muscle behind companies from Netflix to EMC. Any place where someone does heavy lifting on the Internet, you’ll find FreeBSD. Absolute FreeBSD brings FreeBSD’s strengths to bear on your problems. Absolute BSD taught new sysadmins how to build and manage a FreeBSD server. Absolute FreeBSD dove deep into server management, taking you beyond just making things work and into understanding why they work. This third edition of Absolute FreeBSD updated all that knowledge and covers FreeBSD’s newest features. You’ll learn: How to best install FreeBSD to meet your needs Which filesystem to use in your environment How to back up and restore critical data When and how to tweak the kernel, and when not to Network configuration, from activating interfaces to selecting congestion control algorithms Managing both UFS and ZFS, as well as FreeBSD’s other important filesystems FreeBSD’s software packaging system, including how to build your own package repository How and when to upgrade How to build your own FreeBSD Advanced security features like blacklistd and packet filtering Monitoring and Adjusting Performance Container-style virtualization with jails Diskless systems Panic management and bug reporting New readers will still get the solid introduction they need, but fans of the earlier editions will expand their skills still further. All in the inimitable style that has made Lucas’ system administration books so popular.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值