顯示具有 PPTP 標籤的文章。 顯示所有文章
顯示具有 PPTP 標籤的文章。 顯示所有文章

2015年10月5日 星期一

Forward PPTP server packet from Pi

這個問題花了我不少時間去處理,原因居然是因為Rasbian使用的3.18 kernel將PPTP packet視為invalid packet。不過還好後來有找到解決方法,分享給各位。

ping: sendmsg: Operation not permitted
出現以上訊息時代表iptables沒設定好,可重設iptables
# Reset/Flush iptables
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
# Flush end
但須注意此時已經policy設為ACCEPT,為debug使用,記得結束後要將iptables -P 設回需要的policy

PPTP forward參考設定如下

#!/bin/sh
### BEGIN INIT INFO
# Provides:         firewall.sh
# Required-Start:   $all
# Required-Stop:
# Default-Start:    2 3 4 5
# Default-Stop:     0 1 6
### END INIT INFO

INTIF="你的對內介面,如brlan"

INTNET="對內介面的網段"

INTIP="PPTP server的IP"

EXTIF="對外介面,如為撥接通常為ppp0"

#Loading required stateful/NAT kernel modules...

/sbin/depmod -a
/sbin/modprobe ip_tables
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_conntrack_irc
/sbin/modprobe iptable_nat
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ip_nat_irc

#below has to be loaded for pptp
/sbin/modprobe nf_nat_pptp 
/sbin/modprobe nf_conntrack_pptp 
/sbin/modprobe nf_conntrack_proto_gre 
#就是上面這三個kernel需要load,否則再怎麼設都是枉然

echo "1" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/ip_dynaddr

UNIVERSE="0.0.0.0/0"

iptables -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT

iptables -A FORWARD -i $EXTIF -o $INTIF -d $INTIP -j ACCEPT

# Enable SNAT (MASQUERADE) functionality on $EXTIF
iptables -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE

#DMZ setting
iptables -t nat -A PREROUTING -i $EXTIF -p tcp -m multiport --dport 1:65535 -j DNAT --to $INTIP
iptables -t nat -A PREROUTING -i $EXTIF -p udp -m multiport --dport 1:65535 -j DNAT --to $INTIP

# PPTP PREROUTING GRE packets
iptables -t nat -A PREROUTING -i $EXTIF -p 47 -j DNAT --to $INTIP
iptables -A FORWARD -i $EXTIF -p 47 -j ACCEPT

如果不是使用DMZ的話可將DMZ setting改成--dport 1723只轉port 1723到PPTP server就好
另外如果是使用pfsense之類的firewall,INTIP為pfsense的WAN端




將script註冊為service
sudo update-rc.d <script undre /etc/init.d/> defaults
將service移除
sudo update-rc.d -f foobar remove
設定啟動相依性(如在某service啟動後啟動)
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs

2015/10/5更新
遇到一個問題是source ip被snat蓋掉。因為以前使用ddwrt時沒有遇到這個問題,因此研究了一下,發現是需要設-m state --state NEW在iptables裡對應PREROUTING的port。才能夠觸發output。否則單純用MASQUERADE是可以但是就變成snat會將source ip蓋掉變成內部ip,不是我要的。
因此上面#DMZ setting要多增加兩行
iptables -t nat -A INPUT -i $EXTIF -p udp -m state --state NEW -m multiport --dport 1:65535 -j ACCEPT
iptables -t nat -A INPUT -i $EXTIF -p tcp -m state --state NEW -m multiport --dport 1:65535 -j ACCEPT

參考資料
register service
https://mkaz.github.io/2013/07/03/run-script-at-start-on-debian/
setting linux firewall
http://www.aboutdebian.com/firewall.htm
http://www.linuxjournal.com/article/3866
PPTP forward
http://ubuntuforums.org/showthread.php?t=801207
http://www.linuxquestions.org/questions/linux-networking-3/port-forward-gre-and-pptp-using-iptables-210334/
http://serverfault.com/questions/466030/pptp-iptables-routing-issue
https://wiki.archlinux.org/index.php/PPTP_server#iptables_firewall_configuration
https://lists.debian.org/debian-firewall/2004/04/msg00103.html
http://wiki.linuxmce.org/index.php/PPTP_server
tcpdump PPTP packet
http://serverfault.com/questions/342604/how-to-sniff-request-packet-on-vpn-server
DMZ, nat preserve source ip
https://www.debian-administration.org/article/73/Port_forwarding_for_iptables_DMZ


2014年10月30日 星期四

有關mac翻牆問題

最近遇到一個問題是mac要帶去中國翻牆,台灣這邊已經架設好PPTP VPN server,mac也設定好並連上VPN,卻發現IP不是VPN server的IP,翻牆失敗。但是同樣設定windows也設定過好幾台,並沒有遇到這樣的問題,VPN server端也設定all traffic through vpn server。最後search了一下,發現設定好連線之後,要按齒輪,set service order(中文好像是設定服務順序),然後把VPN拖到最上端,就可以讓所有流量都透過VPN傳送了,翻牆成功。

參考資料
http://superuser.com/questions/436434/os-xs-send-all-traffic-over-vpn-connection-seems-to-be-failing

2013年12月9日 星期一

pfsense pptp 807

本來以為807是port filtered造成的,結果發現是一場誤會。(修正:filtered會造成807沒錯,但是是要從內網去test port,如果從外網IP去test會有filtered卻連得上的結果,可能跟中華電信有關)

我出現807時pfsense都會出現這行字 vnode_pager_getpages i/o read error,然後web gui會出現這段並且無法登入,也許出現的字會略不同:
Warning: fopen(/tmp/config.lock): failed to open stream: Device not configured in /etc/inc/util.inc on line 127 Warning: flock() expects parameter 1 to be resource, null given in /etc/inc/util.inc on line 138 Warning: fclose() expects parameter 1 to be resource, null given in /etc/inc/util.inc on line 139 Warning: session_start(): open(/var/tmp//sess_c117ccb8d15b44abd4d463ae8ce44d7c, O_RDWR) failed: No space left on device (28) in /etc/inc/auth.inc on line 1357
搜尋的結果並不是pfsense的問題,我之前還寫了個小程式讓pfsense重啟,短期是有效但是會造成使用中一直中斷也不行,有人說把virtualbox的設定值存放裝置內使用主機I/O快取關閉,這樣可以改用virtualbox內的cache,不過測試結果還是一樣會出現錯誤,可能我硬碟真的loading太大。最後參考了一篇提到,把虛擬硬碟檔案放到與系統碟不同的硬碟存放就可以避免,試了之後也的確有效。注意此處的系統碟不是指WINDOWS安裝的磁區,而是另一顆實體硬碟上的磁區。

另外如果要使用PPPOE則不要在general setup設定DNS server,並且要把之前使用的gateway清除,否則會無法獲取IP。

如果無法獲取IP時便重啟之參考code
ping -n 1 xxx.yyy.zzz.www | findstr TTL && start home.mp3
ping -n 1 xxx.yyy.zzz.www | findstr TTL || start alarm.mp3

參考資料
http://www.vixual.net/blog/archives/32
http://forum.pfsense.org/index.php?topic=39390.0
http://www.techsupportforum.com/forums/f31/windows-7-pptp-vpn-error-807-and-800-a-559778.html
http://answers.microsoft.com/en-us/windows/forum/windows_7-networking/windows-7-pro-pptp-vpn-error-807-and-will-not/6cb8e5a3-a107-4164-bc2b-131a5fc12ba6
http://zh.wikipedia.org/wiki/%E9%BB%9E%E5%B0%8D%E9%BB%9E%E9%9A%A7%E9%81%93%E5%8D%94%E8%AD%B0
http://blog.xuite.net/gp.gp/os/26008367
http://forum.pfsense.org/index.php?topic=57459.0
http://forum.pfsense.org/index.php?topic=53469.5;wap2
http://serverfault.com/questions/396666/batch-ping-ip-and-execute-different-commands-on-return

2013年10月24日 星期四

android內建vpn撥接傳輸速度上不去問題

使用android內建VPN撥接到自己架設的PPTP VPN server播放影片或傳輸檔案時,常會lag或者是傳輸很慢,使用電腦則不會,因此讓我想到也許是android效能不足無法同時處理。或者之後等手機效能趕上時就不會如此,不過目前我得到的暫時解決方案是使用FTP協定,利用Fillazilla ftp server架設伺服器並用es file explorer連入,便可以直接點選檔案並撥放串流,我是用MX Player載入DTS自訂解碼器之後便可以很輕鬆的看影片,也不會再像之前一樣LAG,真的很方便呢。