2008年9月19日 星期五

兩個小技巧

第一個技巧: 在登入畫面上隱藏新建的XP用戶

使用regedit打開登錄資料庫,到 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon\SpecialAccounts\UserList 機碼目錄下,添加名為 <%username> 的DWORD值,預設為0 -->代表隱藏;設為1或刪除則代表顯示。

該目錄下放著的DWORD值都是各個用戶名稱。使用本技巧時要小心一點。


第二個技巧: 使用Green Skype

1. 選定一個目錄來啟用Skype,e.g. D:\Mydoc\Skype
2. 從已經安裝好Skype的PC上,把\Skype\phone\skype.exe 檔複製出來,放到前面這個目錄裏去
3. 在這個目錄裡新建一個子目錄"Data"
4. 在這個目錄建一個啟動Skype的Script (可以先用.bat來試試), 裡面加一行: skype.exe /nosplash /datapath:"Data" /removable

其中:
/nosplash:Don't display the start-up screen
/datapath: : specify where Skype keeps its data and temporary files.
/removable: 表示要求Skype 以可攜模式執行

2008年9月10日 星期三

How to build a pptp VPN connection




PC1:VPN server(Ubuntu 7.10)
eth0: publicIP(61.220.51.26)
eth1: DHCP server(192.168.4.254)
DHCP range: 100-200

PC2:VPN client(WindowsXP sp2)
under NAT(59.124.68.73)
local IP:192.168.1.4

PC3:DHCP client(WindowsXP sp2)
IP:192.168.4.199

Target

Establish a VPN connection between PC1 and PC2,so that PC2 can access PC3's share folders

Notice:Assume that PC1's eth0 can access internet, and PC3 can also access internet though PC1's eth0.

Steps

1.install pptp
sudo apt-get install pptpd

2.There are three files needed to be configured
/etc/pptpd.conf
/etc/ppp/pptpd-options
/etc/ppp/chap-secretsv

3.Modify /etc/pptpd.conf
sudo gedit /etc/pptpd.conf

###############################################################################
# $Id: pptpd.conf 4255 2004-10-03 18:44:00Z rene $
#
# Sample Poptop configuration file /etc/pptpd.conf
#
# Changes are effective when pptpd is restarted.
###############################################################################

# TAG: ppp
# Path to the pppd program, default '/usr/sbin/pppd' on Linux
#
#ppp /usr/sbin/pppd

# TAG: option
# Specifies the location of the PPP options file.
# By default PPP looks in '/etc/ppp/options'
#
option /etc/ppp/pptpd-options

# TAG: debug
# Turns on (more) debugging to syslog
#
#debug

# TAG: stimeout
# Specifies timeout (in seconds) on starting ctrl connection
#
# stimeout 10

# TAG: noipparam
# Suppress the passing of the client's IP address to PPP, which is
# done by default otherwise.
#
#noipparam

# TAG: logwtmp
# Use wtmp(5) to record client connections and disconnections.
#
logwtmp

# TAG: bcrelay
# Turns on broadcast relay to clients from interface
#
#bcrelay eth1

# TAG: localip
# TAG: remoteip
# Specifies the local and remote IP address ranges.
#
# Any addresses work as long as the local machine takes care of the
# routing. But if you want to use MS-Windows networking, you should
# use IP addresses out of the LAN address space and use the proxyarp
# option in the pppd options file, or run bcrelay.
#
# You can specify single IP addresses seperated by commas or you can
# specify ranges, or both. For example:
#
# 192.168.0.234,192.168.0.245-249,192.168.0.254
#
# IMPORTANT RESTRICTIONS:
#
# 1. No spaces are permitted between commas or within addresses.
#
# 2. If you give more IP addresses than MAX_CONNECTIONS, it will
# start at the beginning of the list and go until it gets
# MAX_CONNECTIONS IPs. Others will be ignored.
#
# 3. No shortcuts in ranges! ie. 234-8 does not mean 234 to 238,
# you must type 234-238 if you mean this.
#
# 4. If you give a single localIP, that's ok - all local IPs will
# be set to the given one. You MUST still give at least one remote
# IP for each simultaneous client.
#
# (Recommended)
localip 192.168.4.201 #this is the local ip when you establish a connection
remoteip 192.168.4.202-210 #this are ips will asign to VPN clients
# or
#localip 192.168.0.234-238,192.168.0.245
#remoteip 192.168.1.234-238,192.168.1.245

4.Modify /etc/ppp/pptpd-options
sudo gedit /etc/ppp/pptpd-options

###############################################################################
# $Id: pptpd-options 4255 2004-10-03 18:44:00Z rene $
#
# Sample Poptop PPP options file /etc/ppp/pptpd-options
# Options used by PPP when a connection arrives from a client.
# This file is pointed to by /etc/pptpd.conf option keyword.
# Changes are effective on the next connection. See "man pppd".
#
# You are expected to change this file to suit your system. As
# packaged, it requires PPP 2.4.2 and the kernel MPPE module.
###############################################################################


# Authentication

# (must match the second field in /etc/ppp/chap-secrets entries)
name pptpd

# Optional: domain name to use for authentication
# domain mydomain.net

# Strip the domain prefix from the username before authentication.
# (applies if you use pppd with chapms-strip-domain patch)
#chapms-strip-domain


# Encryption
# Debian: on systems with a kernel built with the package
# kernel-patch-mppe >= 2.4.2 and using ppp >= 2.4.2, ...
# {{{
#refuse-pap
#refuse-chap
#refuse-mschap
require-chap
require-mschap

# Require the peer to authenticate itself using MS-CHAPv2 [Microsoft
# Challenge Handshake Authentication Protocol, Version 2] authentication.
require-mschap-v2
# Require MPPE 128-bit encryption
# (note that MPPE requires the use of MSCHAP-V2 during authentication)
#require-mppe-128
# }}}

# Network and Routing

# If pppd is acting as a server for Microsoft Windows clients, this
# option allows pppd to supply one or two DNS (Domain Name Server)
# addresses to the clients. The first instance of this option
# specifies the primary DNS address; the second instance (if given)
# specifies the secondary DNS address.
ms-dns 168.95.1.1
#ms-dns 166.111.8.29

# If pppd is acting as a server for Microsoft Windows or "Samba"
# clients, this option allows pppd to supply one or two WINS (Windows
# Internet Name Services) server addresses to the clients. The first
# instance of this option specifies the primary WINS address; the
# second instance (if given) specifies the secondary WINS address.
#ms-wins 10.0.0.3
#ms-wins 10.0.0.4

# Add an entry to this system's ARP [Address Resolution Protocol]
# table with the IP address of the peer and the Ethernet address of this
# system. This will have the effect of making the peer appear to other
# systems to be on the local ethernet.
# (you do not need this if your PPTP server is responsible for routing
# packets to the clients -- James Cameron)
proxyarp

# Debian: do not replace the default route
nodefaultroute


# Logging

# Enable connection debugging facilities.
# (see your syslog configuration for where pppd sends to)
debug

# Print out all the option values which have been set.
# (often requested by mailing list to verify options)
#dump


# Miscellaneous

# Create a UUCP-style lock file for the pseudo-tty to ensure exclusive
# access.
lock

# Disable BSD-Compress compression
nobsdcomp

5.Modify /etc/ppp/chap-secrets
sudo gedit /etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client server secret IP addresses
sarosa pptpd 1234 192.168.4.201
vosky pptpd vosky *
#this means VPN server will assign a IP to VPN clients within the remote IP setting in pptpd.conf

6. Restart pptp to let it work
sudo /etc/init.d/pptpd restart

At this point the setting of pptp is complete, but you may not be able to establish connection. Still need to modify iptables to allow VPN connections

7. Modify iptables
add the following rules to your iptables
iptables -t nat -A POSTROUTING -s 192.168.4.0/24 -o eth0 -j SNAT --to 61.220.51.26
iptables -A INPUT -p TCP -i $EIF --dport 1723 -j ACCEPT # pptp VPN

Next we need to config VPN client(PC2)
control pannel -> Network Connections -> create a new connect ->
next -> connect to the network at my working place -> next ->
virtual private network connection -> campany name (input: VoSKY) ->
Host name or IP address (input: 61.220.51.26) -> finish ->Fill in username/password
click "內容" -> goes to "安全性" tag -> uncheck "要求資料加密" -> click "確定"


Now you shuould be able to establish a VPN connection between PC1 and PC2
In PC2's end,try to trace route to 168.95.1.1. Check if it first goes to 192.168.4.201 then goes to 61.220.51.254
Also you can try to access PC3's share folder.

Reference
Ubuntu 下面 pptp VPN 的配置

2008年9月5日 星期五

How to build Multiple OS by using BootITNG

Target
To create mutiple OS.
In this case, WindowsXP_TC,WindowsXP_EN,Ubuntu 8.04,IP-PBX(AsteriskNOW)

Before Start
1. Prepare a new HDD(a 250GB sata2 HDD)
2. Prepare CDs needed,(BootITNG, WindowsXP-TC, WindowsXP-En,Ubuntu 8.04,AsteriskNOW)

Steps
1. First boot
Use BootITNG disc to boot,it will then ask if you want to install BootItNG,follow the instructions to complete installation
Notice: When asked if allowed more than 4 primary partition, click yes



2. Create Partitions

click Partition work,in this example I created partitions list like this
WinXP_TC,20G,NTFS
WinXp_EN,15G,NTFS
Ubuntu 8.04,50G,Linux Native
Ubuntu swap,2G,Linux Swap
IP-PBX,10G,Linux Native
IP-PBX swap,4G,Linux Swap
Data,20G,NTFS



3. Create Boot Menu
Create 4 boot options: WindowsXP_TC, WindowsXP_EN, Ubuntu 8.04, IP-PBX
Notice: When creating Ubuntu 8.04 and IP-PBX, don't forget to fill swap partition into HD-0's 2nd posiition



4. Install WindowsXP_TC
Set WinXP_TC partition to be active(From boot menu, choose it to boot)
Notice:first time you try this, it may tell you that this media is not bootable, it doesn't matter.
Insert WindowsXP_TC CD and boot from it, follow the instructions to finish installation
Notice: You can only see Drive C(20G) and Drive D(20G) during installation

5. Install WindowsXP_EN
Set WinXP_EN partition to be active(From boot menu, choose it to boot)
Notice:first time you try this, it may tell you that this media is not bootable, it doesn't matter.
Insert WindowsXP_EN CD and boot from it, follow the instructions to finish installation
Notice: You can only see Drive C(15G) and Drive D(20G) during installation

6. Install Ubuntu 8.04
Set Ubuntu 8.04 partition to be active(From boot menu, choose it to boot)
Insert installation CD and boot from it, follow the steps
Notice:During partitions setting, choose manual,mount "/" to the 10G space and "swap" to the 2G space
When installation finish, reboot, now you find you only can boot with Ubuntu's grub

7. Set BootITNG back
Insert BootITNG CD and reboot, choose "Reactivate" and then restart
After that , you can not boot Ubuntu by selecting "Ubuntu 8.04" from boot menu

8. Set Ubuntu bootable
Insert Ubuntu 8.04 liveCD and reboot, enter live desktop, then open a terminal window
follow the steps below
a) sudo grub
b) find /boot/grub/stage1 (Note:this will give you location of the boot partition) For me it came back as (hd0,2)
c) root (hd0,2) (note: use whatever comes up in b above)
d) setup (hd0,2)
e) quit
Reboot system, and try to bootUbuntu 8.04 from boot menu,it should work now.

8. Install IP-PBX
We use AsteriskNOW to be our IP-PBX
Set IP-PBX partition to be active(From boot menu, choose it to boot)
Insert AsteriskNOW CD and reboot
Follow the installation steps, choose the "Expert Mode"
During partitions setting, choose manual,mount "/" to the 10G space and "swap" to the 4G space
Finish installation, reboot, now you can boot with AsteriskNOW's grub

8. Set BootITNG back
Insert BootITNG CD and reboot, choose "Reactivate" and then restart

Now you should be able to boot between WindowsXP_TC, WindowsXP_EN, Ubuntu 8.04, and IP-PBX

In Next article, I will introduce how to backup these partitions.

2008年9月4日 星期四

How to Set port forwarding

Network topology
1.PC1: NAT+DHCP server(eth0 for public IP and eth1 for DHCP server)
  eth0 IP: 61.220.51.26
     submask: 255.255.255.0
     gateway: 61.220.51.254
  eth1 IP: 192.168.4.254
     submask: 255.255.255.0
2.PC2: Client1
  WindowsXP,static DHCP(192.168.4.199)
  With port 80 enabled
3.PC3: Client2
  WindowsXP,dynamic DHCP(192.168.4.198)
  With port 8080 enabled

PC2 and PC3 can access internet though PC1

Target
1. disable PC1's SSH port(22)
2. mapping port 80 to PC2
3. mapping port 8080 to PC3

Instructions
1.Modify files already set for iptables(iptables.rules)
#!/bin/sh
##### iptables.rule #####
EIF="eth0" # 對外的網路介面
IIF="eth1" # 對內的網路介面
INNET="192.168.4.0/24" # 內部子網域

# forwarding
# 讓內部網路的封包可以轉送到外部
echo "1" > /proc/sys/net/ipv4/ip_forward

# flush all rules
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X

# 定義 policy
# Policy指的是當進來的封包不屬於rule中的任何一條時,所預設的動作。
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT

# localhost
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# 讓主機主動建立的連線可以進來
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

# 設定主機上提供的服務可讓外部網路存取
iptables -A INPUT -i $EIF -p tcp --dport 22 -j DROP # ssh
iptables -A INPUT -i $EIF -p udp --dport 22 -j ACCEPT
iptables -A INPUT -i $EIF -p tcp --dport 80 -j ACCEPT # http
iptables -A INPUT -i $EIF -p icmp -j ACCEPT #ICMP(ping,...)
# ... 其餘省略

# NAT
iptables -t nat -A POSTROUTING -o $EIF -s $INNET -j MASQUERADE
iptables -t nat -A PREROUTING -p tcp -i $EIF --dport 80 -j DNAT --to 192.168.4.199:80
iptables -t nat -A PREROUTING -p tcp -i $EIF --dport 8080 -j DNAT --to 192.168.4.198:8080

2.reload to let it work
./iptables.rules

Reference:vbird

Ubuntu 6.06使用iftab那Ububtu 8.04呢?

Ubuntu 6.06在記錄網路卡的Mac adress時會存在:iftab這個檔中,但升級到了8.04後這個檔案卻不見了,經過網路的查詢後才知道這個檔案換位置了,這個file換到 /etc/udev/rules.d/70-persistent-net.rules

2008年9月2日 星期二

如何在Ubuntu上設定兩個DHCP然後透過一張網卡上網

延續上一篇的文章(如何設定兩個DHCP在Ubuntu ),現在的情形是這樣的:

目前的機器裡,一共有三張網路卡,而它們的預定的分配情形如下:



eth0 (對外網路),使用一個由ADSL分配給你的IP,為了方便起見,我們將它設為:192.168.1.68
eth1 (對內網路,DHCP-1), 使用192.168.5.0/24網段, gateway:192.168.5.1
eth2 (對內網路,DHCP-2), 使用192.168.6.0/24網段, gateway:192.168.6.1


當你把eth0及eth1分別Assign兩個DHCP Server後,請依照下列的步驟


Step 1: 編輯網路(Interfaces)文件

輸入指令:
sudo gedit /etc/networking/interfaces

編輯檔案:

auto lo
iface lo inet loopback


auto eth0 eth1 eth2
iface eth0 inet static
address 192.168.1.86
netmask 255.255.255.0
network 192.168.1.0
broadcase 192.168.1.255
gateway 192.168.1.1
dns-nameservers 168.95.1.1


iface eth1 inet static
address 192.168.5.1
netmask 255.255.255.0
network 192.168.5.0
broadcase 192.168.5.255
dns-nameservers 168.95.1.1

iface eth2 inet static
address 192.168.6.1
netmask 255.255.255.0
network 192.168.6.0
broadcase 192.168.6.255
dns-nameservers 168.95.1.1

Step2: 讓Ubuntu的Router可以Forward封包的功能
輸入指令
sudo /etc/sysctl.conf

編輯檔案:
net.ipv4.ip_forward=1 這行功能打開,若沒有這行時請自己加入

Step3:設定iptables
輸入指令
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Step4:將上述步驟三auto load 到自動執行檔
1. 新增一個file, 命名為:myiptables
2. 在myiptables這個文件中輸入
#! /bin/bash
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
(有人說要加這行,可以做一些安全性設定,就是打開nat的filter功能,事實上不加也可以)

3. 儲存上述檔案到/root資料夾中,或自行定義的檔案
4. 更改此檔案為可執行檔:
輸入指令:
chmod 700 myiptables


5. 編輯自動執行檔的檔案
輸入指令:
sudo gedit /etc/rc.local

編輯此檔案:在此檔案中加入此兩行程式
/root/myiptables 
exit 0

6. 重新開機

如何設定兩個DHCP在Ubuntu

先描述一下環境,一共有三張網路卡,而它們的預定的分配情形如下:
eth0 (對外網路),使用浮動虛擬IP
eth1 (對內網路,DHCP-1), 使用192.168.5.0/24網段
eth2 (對內網路,DHCP-2), 使用192.168.6.0/24網段

Step 1. 安裝DHCP Server
輸入指令:
sudo apt-get install dhcp3-server

Step 2. 設定Network card 的介面
輸入指令:
sudo gedit /etc/network/interfaces

編輯下列的文檔:
auto loiface lo
inet loopback

auto eth1
iface eth1 inet static
address 192.168.5.254
netmask 255.255.255.0

auto eth2
iface eth2 inet static
address 192.168.6.254
netmask 255.255.255.0

Step 3. Restart 網路設定
輸入指令:
sudo /etc/init.d/networking restart

Step 4. 修改dhcp3-server 文檔
輸入指令:
sudo gedit /etc/default/dhcp3-server

編輯文檔
INTERFACES="eth1 eth2"

Step 5. 修改/etc/dhcp3/dhcpd.conf 文檔
輸入指令
sudo gedit /etc/dhcp3/dhcpd.conf

編輯文檔
將其不必要的內容用#註解,然後輸入以下的設定

subnet 192.168.5.0 netmask 255.255.255.0 {
range 192.168.5.1 192.168.5.253;
option routers 192.168.5.1;
option domain-name-servers 168.95.1.1;
option domain-name-servers ae1.com;
option broadcast-address 192.168.5.255;
default-lease-time 600;
max-lease-time 7200;
}


subnet 192.168.6.0 netmask 255.255.255.0 {
range 192.168.6.1 192.168.6.253;
option routers 192.168.6.1;
option domain-name-servers 168.95.1.1;
option domain-name-servers ae2.com;
option broadcast-address 192.168.6.255;
default-lease-time 600;
max-lease-time 7200;
}


Step 5. Restart DHCP Server
輸入指令:
sudo /etc/init.d/dhcp3-server restart

備註:以上的設定方式只有將DHCP Server安裝在eth1及eth2,但eth1及eth2並無法透過eth0上網,若要這麼做則要修改iptable,或利用ubuntu內建的Firestarter讓eth1或eth2透過eth0上網,但Firestarter是無法同時讓eth1或eth2同時上網,但要達成此情形,則要修改iptable方式來做.我們將在下面的文章介紹