2012年3月24日土曜日

ネットワーク パケットを遅延させる

パケットを遅延させる方法。
まさおのブログ (表): Ubuntu でルータ (IPv4) と組み合わせて使うと応用が効く。
(確認した環境: Ubuntu 10.04)

eth1 から出力されるパケットに 500ms の遅延を追加する。

# tc qdisc replace dev eth1 root netem delay 500ms

(設定の確認)
# tc qdisc show
qdisc netem 8001: dev eth1 root refcnt 2 limit 1000 delay 500.0ms
qdisc pfifo_fast 0: dev eth0 root refcnt 2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1

設定を元に戻す。

# tc qdisc del dev eth1 root netem delay 500ms

(設定の確認)
# tc qdisc show
qdisc pfifo_fast 0: dev eth1 root refcnt 2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
qdisc pfifo_fast 0: dev eth0 root refcnt 2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1

参考:
http://diary.sshida.com/20061103-7-diary.html
http://linux-biyori.sakura.ne.jp/setting/st_netem.php

● network, ネットワーク, packet, パケット, latency, 遅延, 追加, 遅らす, tc, delay, netem

2012年3月22日木曜日

Ubuntu でルータ (IPv4)

Ubuntu PC を NAT ルータ (IPv4) にするときのメモ。
(Ubuntu 10.04)

構成の概要はこんな感じ。

+-----------+           +-----------+           +------+
| Local Net |----[eth1]-| Ubuntu PC |-[eth0]----| 網側 |
+-----------+           +-----------+           +------+

1. NIC を増設。

各インターフェース eth0, eth1 に IP アドレスを設定。
(説明省略)

2. /etc/sysctl.conf を編集

# vi /etc/sysctl.conf

(下記コメントを外す)
net.ipv4.ip_forward=1

3. network を再起動

# /etc/init.d/networking restart

4. 設定を確認

/proc/sys/net/ipv4/ip_forward が 1 になっているか確認する。

# cat /proc/sys/net/ipv4/ip_forward
1

5. iptables で IP masquerade の設定

この設定後、eth1 側から ping で導通チェックする。

# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

6. 起動時に IP masquerade が有効になるように設定

# iptables-save > /etc/iptables

# vi /etc/network/if-pre-up.d/iptables

(下記を記述)
#!/bin/sh
/sbin/iptables-restore < /etc/iptables

# chmod 755 /etc/network/if-pre-up.d/iptables

7. eth1 側に DHCP サーバで IP アドレスが振れるように設定。

下記参照。
まさおのブログ (表): Ubuntu で DHCP サーバ

参考:
http://www.sa-sa-ki.jp/blog/2009/11/ubuntu/

● ルータ, router, PC, IPv4, NAT, masquerade, iptables

2012年3月20日火曜日

Ubuntu で proxy サーバ ( squid )

Ubuntu で proxy サーバを立てる時のメモ。
(Ubuntu 10.04)

1. squid をインストール

apt-get で。

# apt-get install squid

2. squid.conf の設定

# vi /etc/squid/squid.conf

(port を 8080 に設定)
http_port 8080

(アクセス許可ネットワークの設定。既に下記は設定されている)
acl localnet src 192.168.0.0/16

(上記 localnet からのアクセスを許可)
http_access allow manager localhost の下に下記を追加  (※ local"host" ではない local"net")

http_access allow localnet

3. squid を起動 (または再起動)

# /etc/init.d/squid start

( 再起動 )
# /etc/init.d/squid restart

■ basic 認証を追加する設定例

パスワードを設定。

# apt-get install apache2-utils
# htpasswd -c /etc/squid/squidpasswd 

basic 認証を有効化する設定を squid.conf に追加。

# vi /etc/squid/squid.conf

(下記を設定)
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/squidpasswd

■ 多段 proxy の設定例

上位 proxy サーバの IP アドレスが 192.168.10.1 で、ポートが 8080 の場合の例。

# vi /etc/squid/squid.conf

(下記を設定。icp ポート (上位 proxy キャッシュ) を使用しない場合は 7 を設定)
cache_peer 192.168.10.1 parent 8080 7 no-query

(すべてのリクエストを上位 proxy サーバに転送)
never_direct allow all

● squid, proxy, プロキシ, プロキシーサーバ, 設定, 多段, 認証, password, パスワード

2012年3月15日木曜日

svn diff でバイナリファイルを含めてパッチを作る

svn diff で、パッチを作るときに、バイナリファイルも含めた形でパッチを作る方法。
調べようと思ったら、ググり方が難しい。
結構、利用シーンは、あると思う。
リビジョン、リポジトリの指定は適当にアレンジ。

$ svn diff -r N:M --force --diff-cmd /usr/bin/diff -x '-auN --binary' > hogehoge.patch

● Subversion, サブバージョン, svn, diff, 差分, binary, バイナリ, バイナリファイル, patch, パッチ

2012年3月6日火曜日

Ubuntu で CRC32

Linux で、ファイルの CRC32 をお手軽に取得する方法を調べたところ、
標準的なコマンドは無いみたいだ。なんでだ!?
cksum というコマンドがあるが、これはちょっと違う。

Perl スクリプトの crc32 を使うのが手っ取り早いようだ。
Ubuntu の場合、libarchive-zip-perl というパッケージ名で提供。

Perl に依存してしまうが、これが一番早そう。
自分でコードを書けってことなんかな。

# apt-get install libarchive-zip-perl

$ crc32 hogehoge

● CRC32, libarchive-zip-perl, cksum