Archive for the 'FreeBSD' Category

TCP Send/Receive Buffer Size

http://proj.sunet.se/E2E/freebsd.txt
http://proj.sunet.se/E2E/tcptune.html

kern.ipc.maxsockbuf=8388608
net.inet.tcp.sendspace=3217968
net.inet.tcp.recvspace=3217968
net.inet.tcp.rfc1323=1


HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Tcp1323Opts=1
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\TcpWindowSize=[wmax]

設好以後, FTP 的 throughput 提高到 50%, 雖不滿意但可以接受啦…
(原本只能跑到 15%, 還會讓機器 hang 住…)

3 分鐘設好 PXE Boot on FreeBSD

用了個奇怪的標題…(汗)

  1. 安裝 isc-dhcpd
  2. 打開 inetd
    # echo ‘inetd_enable=”YES”‘ >> /etc/rc.conf
  3. 打開 tftpd
    # vi /etc/inetd.conf
    拿掉 tftpd 前面的註解
    # /etc/rc.d/inetd start
  4. 下載 SYSLinux 並解開
    http://syslinux.zytor.com/download.php
  5. 建立 tftpd 的根目錄
    # mkdir /tftpboot
  6. 複製 pxelinux.0, memdisk, menu.c32 到 /tftpboot
    # cd syslinux-3.31
    # cp pxelinux.0 /tftpboot
    # cp com32/modules/menu.c32 /tftpboot
    # cp memdisk/memdisk /tftpboot
    找不到的話可以用 find 找
  7. 設定 dhcpd.conf
    allow booting;
    allow bootp;
    option domain-name "example.org";
    option domain-name-servers 10.0.0.1;
    subnet 10.0.0.0 netmask 255.255.255.0 {
            range 10.0.0.128 10.0.0.200;
            option routers 10.0.0.1;
            next-server 10.0.0.1;
            filename "pxelinux.0";
    }
    
  8. 打開 dhcpd
    # echo ‘dhcpd_enable=”YES”‘ >> /etc/rc.conf
    # /usr/local/etc/rc.d/dhcpd start
  9. 設定開機選單
    # mkdir /tftproot/pxelinux.cfg
    # vi /tftproot/pxelinux.cfg/default
  10. # 預設用 menu.c32 這個核心來啟動,即出現選單
    DEFAULT menu.c32
    # 不要用 prompt 的方式,即啟用選單
    PROMPT 0
    # 不要該使用者有選擇權
    # 例如更改啟動參數或直接離開選單
    ALLOWOPTIONS 0
    # 選單的提示時間,50 指 5 秒
    TIMEOUT 50 
    
    # 選單的標題
    MENU TITLE PXELinux Menu 
    
    # 名稱
    LABEL freebsd54
    # 選單上顯示的名稱
    MENU LABEL BSD
    # 用來啟動影像檔的核心,pxelinux提供
    kernel memdisk
    # 要載入的影像檔及參數
    # 此例為將 bsd 的 bootonly CD
    # 所做成的 PXE 影像檔 (註一)
    append initrd=fbsd61.img c=812 h=255 s=63 
    
    LABEL local
    # MENU DEFAULT 是指預設選項
    MENU DEFAULT LOCAL
    # 直接以硬碟開機
    LOCALBOOT 0 
    
    LABEL dos
    MENU LABEL DOS
    kernel memdisk
    # 將磁片做成影像檔後,直接放進來就可以用了
    # 不用加參數,下面的也都是直接用磁片所做成的影像檔
    append initrd=dos.img 
    
    LABEL ghost2003
    MENU LABEL ghost2003
    kernel memdisk
    append initrd=ghost2003.img
    

參考資料:
http://forum.rackred.com/showthread.php?t=2 (註一)
http://blog.rackred.com/2006/05/25/pxe-boot-freebsd-6x/
http://syslinux.zytor.com/pxe.php
http://phorum.study-area.org/viewtopic.php?t=40863

*BSD Stats

Updated: 忘了附上 bsdstats 的網站: http://www.bsdstats.org/

有圖有真相,台灣目前第6名:

untitled

有興趣的人可以裝起來,讓全世界知道FreeBSD也是很多人在用的!

下面附上台灣*BSD數量的統計圖。綠色是*BSD,藍色是FreeBSD的數目。

bsdstats

Summer of Code for FreeBSD

Link: http://www.freebsd.org/projects/summerofcode.html

NFS lockd 也在裡面…還有 Suspend to disk.

fusefs

fusefs 是一個 userland filesystem, 可以讓你使用在 operator 群組內的 user (不一定要是 root) 來 mount 某些奇怪的 fs, 像是 sshfs, gmailfs, flickrfs, smbnetfs, blogfs, wikipediafs, bittorrentfs

另外有 ftpfs, 但是看到是 perl based 的就不太想用了 :Q  也許找套好一點的 ftp library 來生 C 版本的 ftpfs
BTW, 不知道能不能作一個 encoding translation fs,  實際存 unicode, 根據 shell 的 LC_CTYPE 來轉成正確的 encoding…XD

jail

前幾天聽 DK 大長輩 提到 jail,於是今天決定來玩玩看,並且把廣播移到 jail 裡面跑。
目前看起來還不賴,以後就可以在 jail 裡面惡搞了 XD

Reference: http://1513a.mis.yzu.edu.tw/~ant/FNP/System/jail.php

IPSec 設定筆記

參考

http://taosecurity.blogspot.com/2005/01/ipsec-tunnels-with-freebsd-although.html

  1. 修改 Kernel,加上

    options FAST_IPSEC
    device crypto

    並且重開機。

  2. 安裝 security/ipsec-tools
  3. 設定 /usr/local/etc/racoon/racoon.conf:

    path pre_shared_key "/usr/local/etc/racoon/psk.txt";
    padding
    {
    maximum_length 20; # maximum padding length.
    randomize off; # enable randomize length.
    strict_check off; # enable strict check.
    exclusive_tail off; # extract last one octet.
    }

    listen
    {
    isakmp (MY_IP) [500];
    }
    timer
    {
    # These value can be changed per remote node.
    counter 5; # maximum trying count to send.
    interval 20 sec; # maximum interval to resend.
    persend 1; # the number of packets per send.

    # maximum time to wait for completing each phase.
    phase1 30 sec;
    phase2 15 sec;
    }
    remote
    [500]
    {
    #exchange_mode main,aggressive;
    exchange_mode aggressive,main;
    doi ipsec_doi;
    situation identity_only;

    my_identifier user_fqdn “sakane@kame.net”;
    peers_identifier user_fqdn “sakane@kame.net”;
    #certificate_type x509 “mycert” “mypriv”;

    nonce_size 16;
    lifetime time 1 min; # sec,min,hour

    proposal {
    encryption_algorithm 3des;
    hash_algorithm sha1;
    authentication_method pre_shared_key;
    dh_group 2;
    }
    }

  4. 設定 /usr/local/share/psk.txt:
  5. 設定 /etc/ipsec.conf:
    flush;
    spdflush;spdadd any -P out ipsec
    esp/tunnel/-/require;
    spdadd any -P in ipsec
    esp/tunnel/-/require;

    spdadd / any -P out ipsec
    esp/tunnel/-/require;

    spdadd / any -P in ipsec
    esp/tunnel/-/require;

  6. /usr/local/etc/rc.d/racoon.sh start; /etc/rc.d/ipsec start;

P.S.
racoon 的範例設定檔在 /usr/local/share/examples/ipsec-tools 裡面。

自動擋暴力 try ssh 的 script (with pf, ipfw, or ipfw2)

http://www.csie.nctu.edu.tw/~jnlin/script/sshit.txt
http://www.csie.nctu.edu.tw/~jnlin/script/sshit.conf

這個 script 是要改 syslog.conf 的版本。
如果 sshit 原作者沒問題,就把他作成 ports 吧!

自動擋暴力 try ssh 的 script (with pf)

從 http://anp.ath.cx/sshit/sshit.pl 改進的,現在不會 fork 一堆出來了。
這個版本是用 tail -F 讀 /var/log/auth.log,跟 sshit.pl 的作法不同。

Link: http://www.csie.nctu.edu.tw/~jnlin/script/chkfw_select_pf.txt

你必須要在 /etc/pf.conf 加上:

table <$PF_TABLE> persist
block on $extdev from <$PF_TABLE> to any

才會真正 block 有惡意者的 IP。

ng_netflow 的使用方法

# /usr/sbin/ngctl -f- <<-SEQ
mkpeer fxp0: tee lower right
connect fxp0: fxp0:lower upper left
mkpeer fxp0:lower netflow right2left iface0
name fxp0:lower.right2left netflow
msg netflow: setifindex { iface=0 index=5 }
connect fxp0:lower netflow: left2right iface1
msg netflow: setifindex { iface=1 index=6 }
mkpeer netflow: ksocket export inet/dgram/udp
msg netflow:export connect inet/127.0.0.1:9991
SEQ