#44 VPN 与 NAT(续)
开发工具 计算机网络 VPN NAT iptables 2023-04-232021/05/09,VPN 与 NAT 讲了我使用 Windows route 命令和 Linux iptables 命令做 NAT,实现 Windows 机器的 VPN 流量走 Linux 的指定网络设备。
现在情况可能会发生一些新的变化,所以这里记录一下我的几点思路。
coding in a complicated world
2021/05/09,VPN 与 NAT 讲了我使用 Windows route 命令和 Linux iptables 命令做 NAT,实现 Windows 机器的 VPN 流量走 Linux 的指定网络设备。
现在情况可能会发生一些新的变化,所以这里记录一下我的几点思路。
之前用过 Sunny-Ngrok,注册一个账号,有免费的套餐,有很多种方式部署使用。
刚发现现在要搞实名认证,而且只有付费才能使用。
在网上搜索了一下,发现一个好用的内网穿透工具:内网云。免费,然后更方便。
不需要注册,用的 SSH 方案,只需要一行 ssh 命令,做一个远程端口转发,就能实现内网穿透。
给了我这样的开发者非常大的便利。希望能一直用下去~
ssh -R 80:127.0.0.1:8080 sh@sh3.neiwangyun.net
Welcome to network server by neiwangyun.net
current server node : sh3.neiwangyun.net
----------------------------------------------------------
Basic Tunnel Information
username : sh
type : anonymous
subdomain : sxxelgxzm6efshsh3.neiwangyun.net
remote_ip : 121.60.84.218
bandwidth : 2 Mbps
expire_time : 2 hours
unid : d8scvjne5lt2c3svr2rny...
----------------------------------------------------------
Local Server
local server: 127.0.0.1:8000
----------------------------------------------------------
Access to the Tunnel
cname : not support
http : http://sxxelgxzm6efshsh3.neiwangyun.net
https : https://sxxelgxzm6efshsh3.neiwangyun.net
ipport : sxxelgxzm6efshsh3.neiwangyun.net:25207
----------------------------------------------------------
Ctrl+C Exit Process
读到微信公众号文章 本地如何配置多个 GitHub/Gitee 账号?,想起了几年前,面对这样的需求,我自己也是这么操作的。
看到有篇文章说是 git “新增”了 switch 和 restore 两个命令,仔细一看,原来就是 2019 年就引入了的两个命令,不过我确实没有用过。
这里重新整理一下现在 git 的命令。
git version
git version 2.30.2
apt list --installed | grep ^git
git-doc/hirsute,hirsute,now 1:2.30.2-1ubuntu1 all [已安装]
git-extras/hirsute,hirsute,now 6.1.0-1 all [已安装]
git-flow/hirsute,hirsute,now 1.12.3-1 all [已安装]
git-man/hirsute,hirsute,now 1:2.30.2-1ubuntu1 all [已安装,自动]
git-svn/hirsute,hirsute,now 1:2.30.2-1ubuntu1 all [已安装]
git/hirsute,now 1:2.30.2-1ubuntu1 amd64 [已安装]
gitg/hirsute,now 3.32.1-1 amd64 [已安装]
gitk/hirsute,hirsute,now 1:2.30.2-1ubuntu1 all [已安装]
我公司办公环境需要用到 OpenVPN,之前允许一个账号在两处登录,现在处于安全考虑只允许一处登录了。
然后,我就不方便了,因为我办公环境有两台电脑(台式机 Windows,笔记本 Ubuntu)都需要接入 VPN。
检查端口可连接性,并支持检测操作系统信息、占用端口的常见应用程序。
关闭或过滤(Closed|Filtered)
默认扫描常用端口
nmap 192.168.31.0/24
# Ping扫描
nmap -sn 192.168.31.0/24
# 快速端口扫描
nmap -F 192.168.31.0/24
# 操作系统
sudo nmap -O -v 192.168.31.42
sudo nmap -A -v 192.168.31.42 # 输出更详细
# 常规检查:端口(-sV)和操作系统(-O)
sudo nmap -sV -O 192.168.31.42
# 检查指定端口
nmap -p 22 192.168.31.42
nmap -p 22,80,443,3306 192.168.31.42
# 所有端口
nmap -p 1-65525 192.168.31.42
nmap -p- 192.168.31.42
# 加上使用这个端口的服务版本信息
nmap -p 22 192.168.31.42 -sV
# 对端口进行探测
nmap -PS 192.168.31.42 # SYN
nmap -PA 192.168.31.42 # ASK
nmap -PU 192.168.31.42 # UDP
sudo nmap -sS 192.168.1.1-10 # SYN
sudo nmap -sA 192.168.31.0/24 # ACK
sudo nmap -sF 192.168.31.0/24 # FIN
sudo nmap -sN 192.168.31.0/24 # TCP Null
sudo nmap -sT 192.168.31.0/24 # TCP Connect
sudo nmap -sU 192.168.31.0/24 # UDP
sudo nmap -sO 192.168.31.0/24 # IP 协议扫描
nmap -O 192.168.0.1/16
nmap -sP 192.168.0.1/16
nmap -sSU 192.168.1.1/24
# Ping Scan
# Parallel DNS resolution
# SYN Stealth Scan
# UDP Scan
Windows CMD 太挫,中文字体选择少,XP, Win7 下只有点阵字体 (fixedsys) 和新宋体,Win10 字体又多了几个,但效果页不太好。
不过 Win10 的话,可能是半年前吧,微软新出来了一个 Windows Terminal 的虚拟终端,就现代化多了。现在我在 Windows 下(偶尔)一般都是用的新版 Terminal + PowerShell,听方便。
但如果由于 OS 版本等问题,离不开 cmd 的话,有两个方法,一个是使用第三方终端模拟器,比如 cmder;再一个就是想办法定制一下 cmd 的字体。
我在这里记录一下之前使用的一个方案失效地址(确认有效,不过好久都没有用了)。
在 StackOverflow 上看到好些种快速创建文件的命令,逐个测试,在 Ubuntu 下可用的方法有以下几种:
time dd if=/dev/zero of=test.img bs=10M iflag=fullblock,count_bytes count=10G
# 0.00s user 0.45s system 1% cpu 39.144 total
# 在 xfsprogs 包中:
# -n 表示不写入数据
time xfs_mkfile -n 10g test.img
# 0.01s user 0.01s system 2% cpu 0.669 total
# 在 VBox 挂载的虚拟磁盘上执行时遇到 “不支持的操作” 错误
# 在 EXT4 磁盘上没有遇到问题,速度很快
time fallocate -l 10G test.img
time truncate -s 10G test.img
# 0.00s user 0.00s system 46% cpu 0.005 total
time dd if=/dev/zero of=test.img bs=1 count=0 seek=10G
# 0.00s user 0.00s system 77% cpu 0.002 total
最后看到的 dd seek
方案深得征信深得朕心。
根据这个思路,Python 创建 10G 的文件应该这么写(也是我一直以来的写法):
GB = 1 << 30
with open('test.img', 'w') as _file:
_file.seek(10 * GB - 1)
_file.write(chr(0))
PowerShell 的最近的一次更新修复了其作为 SSH 的登录 Shell 的一些问题。
Win 10 对 NFS,SSH 的支持推进也是有目共睹。
随着 MS 对 Windows 的策略调整,估计以后 Windows 服务器也会变多。
# Download the Microsoft repository GPG keys
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb
# Update the list of products
sudo apt-get update
# Enable the "universe" repositories
sudo add-apt-repository universe
# Install PowerShell
sudo apt-get install -y powershell
# Start PowerShell
pwsh
# 获取本地 IP
(invoke-webrequest -uri "http://ifconfig.me/ip").content
get-nettcpconnection | where-object {$_.State -eq "Listen"}
get-nettcpconnection -localport 49667
get-process -id (get-nettcpconnection -localport 49667).owningprocess
stop-process -id (get-nettcpconnection -localport 11).owningprocess
"# README" | out-file README.md
type README.md
git log --diff-filter=A --follow --format="%h %ad %ce" -1 -- requirements.txt | cat
# 6a0eebf 2019-05-22 19-47-09 bobo@example.com