跳转至

network

Web Server: Nginx V.S. Apache2

常见的web服务器

常见的web服务器有Apache、nginx、IIS

  1. Apache
    1. Apache音译为阿帕奇, 是全世界最受欢迎的web服务器,因其快速、可靠并且可通过简单的API扩充,能将Python\Perl等解释器部署在其上面等优势,受到广泛的关注与使用。
    2. 但是现在用的人少了,而且性能没nginx好
  2. nginx
    1. Apache的致命缺陷就是在同时处理大量的(一万个以上)请求时,显得有些吃力,所以“战斗民族”的人设计的一款轻量级的web服务器——nginx, 在高并发下nginx 能保持比Apache低资源低消耗高性能 ,
  3. IIS
    1. iis是Internet Information Services的缩写,意为互联网信息服务,是由微软公司提供的基于运行Microsoft Windows的互联网基本服务,

查找网站服务

判断是nginx还是apach2

随便输出返回404页面显示 nginx/1.14.0 (Ubuntu)

命令

sudo service apache2 status
sudo service nginx status
sudo vim /etc/ssh/sshd_config
#PasswordAuthentication yes
sudo service ssh restart

nginx

配置文件

  1. /etc/nginx/nginx.conf
  2. 全局块、
  3. events块
  4. http块
    1. http全局块
    2. 多个server块
      1. server全局块
      2. 多个location块
        1. Nginx中location的作用是根据Url来决定怎么处理用户请求(转发请求给其他服务器处理或者查找本地文件进行处理)。location支持正则表达式,配置十分灵活。我们可以在一个虚拟主机(nginx中的一个server节点)下配置多个location以满足如动静分离,防盗链等需求。

全局块

全局块是默认配置文件从开始到events块之间的一部分内容,主要设置一些影响Nginx服务器整体运行的配置指令,因此,这些指令的作用域是Nginx服务器全局。

# 指定可以运行nginx服务的用户和用户组,只能在全局块配置
user www-data;
# 指定工作线程数
worker_processes auto;
# 指定pid文件存放的路径,这个指令只能在全局块配置
pid /run/nginx.pid;
# include指令,用于包含其他的配置文件,可以放在配置文件的任何地方,但是要注意你包含进来的配置文件一定符合配置规范,比如说你include进来的配置是worker_processes指令的配置,而你将这个指令包含到了http块中,着肯定是不行的,上面已经介绍过worker_processes指令只能在全局块中。
include /etc/nginx/modules-enabled/*.conf;

events块

events 模块用于配置 Nginx 的事件处理机制。事件可以是网络连接、定时器等。一般来说,你不太需要直接修改 events 模块的配置,除非你对 Nginx 的事件处理机制有特殊的需求。默认的配置通常是适用于大多数情况的。

events {
    ; worker_connections 配置项定义每个 worker 进程可以同时处理的连接数
    worker_connections  768;
}

html块

http 模块是配置 Nginx HTTP 服务器的主要部分。在这个模块中,你可以配置服务器的行为、代理、日志、gzip 压缩等等。这是你放置虚拟主机(server 块)配置的地方。

http {
        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

include /etc/nginx/sites-enabled/*;是最重要的。

include /etc/nginx/sites-enabled/*
  • 在 Nginx 中,文件加载和生效的顺序是由 include 指令定义的。如果在这些文件中有重复的配置,后加载的配置将覆盖先加载的配置。因此,后加载的配置文件具有更高的优先级
  • 默认server块在/etc/nginx/sites-enabled/default
  • 默认填写了root /var/www/html;
server {
        listen 80 default_server;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
}
新配置
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
server {
      listen 80;
      listen [::]:80;

      server_name example.com;

      root /var/www/example.com;
      index index.html;

      location / {
              try_files $uri $uri/ =404;
      }
}

Ubuntu 18.04下 Apache2 web 服务器的安装 (在node5测试)

httpd是Apache超文本传输协议(HTTP)服务器的主程序。被设计为一个独立运行的后台进程,它会建立一个处理请求的子进程或线程的池。

sudo apt install apache2 -y

判断是否正常运行

systemctl status apache2
service apache2 status

开启、关闭和重启服务器,需要sudo

/etc/init.d/apache2 start    //启动Apache服务
/etc/init.d/apache2 stop    //停止Apache服务 
/etc/init.d/apache2 restart    //重启Apache服务

修改根目录/把文件传到根目录下

vim /etc/apache2/sites-available/000-default.conf
    DocumentRoot /var/www/html    // 默认
    DocumentRoot /home/shaojiemike/Network/HUGO/shaojiemike/public //但是没有访问文件的权限,最后是把静态网页放到/var/www/html下
sudo apache2ctl -k restart //重启

基础配置解释

默认内网

  • You should replace this file (located at /var/www/html/index.html) before continuing to operate your HTTP server.
  • Configuration Overview
  • Ubuntu's Apache2 default configuration is different from the upstream default configuration, and split into several files optimized for interaction with Ubuntu tools.
  • The configuration system is fully documented in /usr/share/doc/apache2/README.Debian.gz. Refer to this for the full documentation. Documentation for the web server itself can be found by accessing the manual if the apache2-doc package was installed on this server.
  • The configuration layout for an Apache2 web server installation on Ubuntu systems is as follows:

  • /etc/apache2/ |-- apache2.conf | `-- ports.conf |-- mods-enabled | |-- *.load | `-- *.conf |-- conf-enabled | `-- *.conf |-- sites-enabled | `-- *.conf

  • apache2.conf is the main configuration file. It puts the pieces together by including all remaining configuration files when starting up the web server.

  • ports.conf is always included from the main configuration file. It is used to determine the listening ports for incoming connections, and this file can be customized anytime.
  • Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/ directories contain particular configuration snippets which manage modules, global configuration fragments, or virtual host configurations, respectively.
  • They are activated by symlinking available configuration files from their respective *-available/ counterparts. These should be managed by using our helpers a2enmod, a2dismod, a2ensite, a2dissite, and a2enconf, a2disconf . See their respective man pages for detailed information.
  • The binary is called apache2. Due to the use of environment variables, in the default configuration,
  • apache2 needs to be started/stopped with /etc/init.d/apache2 or apache2ctl.
  • Calling /usr/bin/apache2 directly will not work with the default configuration.
  • Document Roots
  • By default, Ubuntu does not allow access through the web browser to any file apart of those located in /var/www, public_html directories (when enabled) and /usr/share (for web applications).
  • If your site is using a web document root located elsewhere (such as in /srv) you may need to whitelist your document root directory in /etc/apache2/apache2.conf.
    • 最简单实现mount -t none -o bind,ro /targetPath /var/www/html
  • The default Ubuntu document root is /var/www/html. You can make your own virtual hosts under /var/www. This is different to previous releases which provides better security out of the box.

遇到的问题

把静态网页传上去

$ sudo apache2ctl -k restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message

没有访问权限

Forbidden
You don't have permission to access / on this server.

这是因为没有修改运行访问的目录,而且能通过别名

sudo vim apache2.conf
    alias /testtsj/ "/home/shaojiemike/Network/"
    <Directory "/home/shaojiemike/Network/">
        Options Indexes FollowSymLinks #首页不存在,允许访问当前目录下其它内容
        AllowOverride None
        Require all granted #允许访问所有
    </Directory>

testtsj

参考文献

https://blog.csdn.net/weixin_39212776/article/details/81192847

https://blog.csdn.net/weixin_41843699/article/details/90390562

Cloudflare warp proxy

简介

  • Cloudflare 作为全球最大的网络服务提供商,全球大约有30%的网络服务由它提供。
  • WARP是Cloudflare提供的免费的,没有带宽上限或限制的VPN服务,可以让你在任何地方访问互联网,而不会受到地域限制。
  • WARP软件是基于wireguard魔改的。
  • WARP有安卓和Windows的客户端,但是使用人数过多,体验并不好
  • Linux下通过WARP代理能实现20MB/s的下载速度。

WARP on Linux

安装配置

  • 缘由:WARP下的PT做种快得多。(不是,是因为网络硬盘,所以下载多少要占用多少上传)
  • 参考教程
  • 脚本和所需文件在Z:\shaojiemike\Documents\文献\计算机网络目录下。这里先使用fjw的脚本。

  • 通过注册脚本register.py,获得私钥和分配的ip

  • 配置wg。其中Endpoint端口可从官方文档中找到,默认的2408很可能被封。WARP with firewall · Cloudflare Zero Trust docs
    [Interface]
    PrivateKey = xxxx         #register.py的私钥
    Address = xxx/32,xxx/128  #register.py的ipv4和ipv6
    Table = off              # off禁止wg修改路由表
    
    [Peer]
    PublicKey = bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=
    AllowedIPs = 0.0.0.0/0,::/0
    Endpoint = [2606:4700:d0::a29f:c001]:500    #2408, 1701, 500, 4500
    PersistentKeepalive = 25
    
  • warp使用的不是标准的wg协议,root下运行,需要通过一个nft脚本main.sh修改包的3个字节。
  • 安装nft apt-get install nftables
  • 需要/etc/default/warp-helper文件填写对应的
  • ROUTING_ID对应register.py的ROUTING_ID。注意三个数之间没空格
  • UPSTREAM对应wg-conf里Endpoint。比如:
  • ROUTING_ID=11,45,14 UPSTREAM=[2606:4700:d0::a29f:c001]:500
  • 最后开启路由表,Root权限运行ip route add default dev warp proto static scope link table default

WARP on OpenWRT

  • 目的:为了防止大量流量通过WARP,导致被官方封禁,所以只在OpenWRT上配置WARP分流github的流量。
  • 实现思路:
  • 运行python脚本,通过github的API获得所有的github域名ip,
  • 使用iptables的warp_out表,将目的地址为github域名ip路由到WARP的虚拟网卡上。

WARP Wireguard Establishment

python register.py #自动生成warp-op.conf,warp.conf和warp-helper
mv warp-helper /etc/default
# cat main.sh
# cat warp-op.conf
vim /etc/config/network #填写warp-op.conf内容,默认只转发172.16.0.0/24来测试连接
ifup warp #启动warp, 代替wg-quick up warp.conf
bash main.sh #启动防火墙实现报文头关键三字节修改
nft list ruleset #查看防火墙,是否配置成功
wg #查看warp状态,测试是否连接成果

这时还没创建warp_out路由表,所以还不能通过WARP出数据。

#/etc/config/network
config interface 'warp'
        option proto 'wireguard'
        option private_key 'wKpvFCOk4sf8d/RD001TF7sNQ39bWnllpqaFf8QnHG4='
        option listen_port '51825'
        list addresses '172.16.0.2/32'
        list addresses '2606:4700:110:8466:d4ea:ffb8:10da:470f/128'
        #option disabled '1' 
然后WebUI点击apply 或者命令行运行ifconfig warp down && ifup

Network planning and design

添加了WARP的网络出口后,路由器不在只是通过WAN出数据。防火墙需要更新:

  • 原路返回规则。
  • 针对有公网ip的接口,需要原路返回。
    • 配置来自wan和WARP的信报,使用wan和WARP的路由表,优先级3
    • 来自wan的比如来自外部的ssh,为了防止失联。
    • 来自WARP的比如wget --bind-address=WARP_ip来模拟
  • 内网地址没有必要配置,因为通过内网地址访问host,则dst必然也是内网地址。因此会匹配main中的内网地址规则。
  • wan和WARP的路由表内各自走wan和WARP的网卡
  • 为了使得原本wg正常运行,10: from all lookup main suppress_prefixlength 1
  • 假如warp_out是defualt规则,该项也是为了防止失联。
  • 创建warp_out的空路由表1000: from all lookup warp_out,优先级1000
root@tsjOp:~/warp# ip rule
0:      from all lookup local
3:      from 114.214.233.141/22 iif eth1 lookup wan
3:      from 172.16.0.2 iif warp lookup warp
10:     from all lookup main suppress_prefixlength 1
1000:   from all lookup warp_out
32766:  from all lookup main
32767:  from all lookup default

填充warp_out路由表

cd ip_route
mv ../github_ipv4.txt .
python fill_ip_table.py --table warp_out --iface warp --p2p -f github_ipv4.txt

对所有github域名的ip执行类似ip ro add 192.30.252.0/22 dev warp proto static table warp_out操作。

测试

mtr www.github.com
ssh -vT [email protected]
git clone https://github.com/llvm/llvm-project

添加到启动项

修改/etc/rc.local

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.


sleep 30 && cd /root/warp/ip_route && python fill_ip_table.py --table warp_out --iface warp --p2p -f github_ipv4.txt

/root/warp/main.sh #重新添加防火墙

exit 0

WARP on Windows

基于1.1.1.1 的安装windows版本直接白嫖

需要进一步的研究学习

暂无

遇到的问题

暂无

开题缘由、总结、反思、吐槽~~

参考文献

https://gist.github.com/iBug/3107fd4d5af6a4ea7bcea4a8090dcc7e

glados

Network InterConnect

不同带宽与距离的互连技术

System Area Network(系统域网):主机及外设 Local Area Network(局域网):以太网 Metropolitan Area Network(城域网):WiMax Wide Area Network(广域网):因特网,X.25

没有公网IP: FRP反向代理

需要进一步的研究学习

暂无

遇到的问题

暂无

开题缘由、总结、反思、吐槽~~

如果在外地,需要访问单位或者家庭的内网:

用ipv6,通过VPN(wireguard)连接到我寝室的路由器,然后通过路由器上网,所以可以访问校内网络。

台式机不关机,用台式机的wireguard也可以访问。

参考文献

Family Wi-Fi

Wi-Fi

Wi-Fi是一个创建于IEEE 802.11标准的无线局域网技术。基于两套系统的密切相关,也常有人把Wi-Fi当做IEEE 802.11标准的同义术语。

Wi-Fi这个术语被人们普遍误以为是指无线保真(Wireless Fidelity),并且即便是Wi-Fi联盟本身也经常在新闻稿和文件中使用“Wireless Fidelity”这个词,Wi-Fi还出现在ITAA的一个论文中。但事实上,Wi-Fi一词没有任何意义,也是没有全写的。

WiFi4/5/6

WIFI6 是802.11ax协议,支持2.4GHz和5GHz,支持更多的技术,更高的调制方式。比如 1. 调制模式方面,WiFi 6 支持 1024-QAM,高于 WiFi 5 的 256-QAM,数据容量更高,意味着更高的数据传输速度; 2. 此外,WiFi 6 加入了新的 OFDMA 技术,支持多个终端同时并行传输,有效提升了效率并降低延时,这也就是其数据吞吐量大幅提升的秘诀。 3. WiFi6通过更优质的Long DFDM Symbol发送机制,将每个信号载波发送时间从WiFi5的3.2μs提升到12.8μs,有效降低丢包率和重传率,使传输更加稳定。 4. WiFi6容量更大:多用户MU-MIMO技术允许电脑讯网时间多终端共享信道,使多台手机/电脑一起同时上网,从此前低效的排队顺序通过方式变成为“齐头并进”的高效方式。

各种网络及速率

无线路由器发展到现在有IEEE802.11b、IEEE802.11g、IEEE802.11a、IEEE802.11n、IEEE802.11ac标准,对应的无线速率分别是11Mbps、54 Mbps、150 Mbps、300Mbps、1Gbps。这里的无线速率指的是无线传输通过的最高速率。

这里拿300Mbps的无线路由器速率来说一下路由器的传输速度,300Mbps无线路由器指的是传输和接收最大能通过的速率,一般看到的只是传输的速度,也就是只能看到一半的速度,也就是150Mbps,这个是理论速率,但是在实际使用过程中由于环境的干扰,会有衰减。所以在实际使用过程中都只剩下110 Mbps左右。

WLAN

WLAN是Wireless Local Area Network的简称,指应用无线通信技术将计算机设备互联起来。

WLAN起步于1997年。当年的6月,第一个无线局域网标准IEEE802. 11正式颁布实施,为无线局域网技术提供了统一标准,但当时的传输速率只有1~2 Mbit/s。随后,IEEE委员会又开始制定新的WLAN标准,分别取名为IEEE802.11a和IEEE802. 11b。IEEE802. llb标准首先于1999年9月正式颁布,其速率为11 Mbit/s。经过改进的IEEE802. 11a标准,在2001年年底才正式颁布,它的传输速率可达到54 Mbit/s,几乎是IEEE802. llb标准的5倍。尽管如此,WLAN的应用并未真正开始,因为整个WLAN应用环境并不成熟。

目前使用最多的是802. 11n(第四代)和802. 11ac(第五代)标准,它们既可以工作在2.4 GHz频段也可以工作在5 GHz频段上,传输速率可达600 Mbit/s(理论值)。但严格来说只有支持802. 11ac的才是真正5G,现来在说支持2.4 G和5G双频的路由器其实很多都是只支持第四代无线标准,也就是802. 11n的双频,而真正支持ac 5G的路由最便宜的都要四五百元甚至上千元。

移动网络

4G与5G的区别

在有线介质上传播数据,想要高速很容易,实验室中,单条光纤最大速度已达到了26Tbps。

无线电磁波传播,才是瓶颈。

3/4/5G的频率

3G的四种标准和频段:CDMA2000、WCDMA、TD-SCDMA、WiMAX,1880MHz-1900MHz和2010MHz-2025MHz。

4G的频率和频段是:1880-1900MHz、2320-2370MHz、2575-2635MHz。

我国的5G初始中频频段,3.3-3.6GHz、4.8-5GHz两个频段。24.75-27.5GHz、37-42.5GHz高频频段正在征集意见。国际上主要使用28GHz进行试验

路由器

MAC地址20-6B-E7-DB-D7-33

WAN口与LAN口

WAN是英文Wide Area Network的首字母所写,即代表广域网;而LAN则是Local Area Network的所写,即本地网(或叫局域网)。WAN口主要用于连接外部网络,而LAN口用来连接家庭内部网络,两者主要会在标识上面有区别,此外大部分路由器的WAN口只有一个,LAN口则有四个或以上。

管理界面

根据路由器背面的提示登陆,可以修改Wi-Fi名称密码、限制设备上下行速率以及黑名单设备。(注意关闭clash代理

DHCP服务器

Dynamic Host Configuration Protocol动态主机配置协议是一个局域网的网络协议。指的是由服务器控制一段IP地址范围,客户机登录服务器时就可以自动获得服务器分配的IP地址和子网掩码。担任DHCP服务器的计算机需要安装TCP/IP协议,并为其设置静态IP地址、子网掩码、默认网关等内容。

采用DHCP方式对上网的用户进行临时的地址分配。也就是你的电脑连上网,DHCP服务器才从地址池里临时分配一个IP地址给你,每次上网分配的IP地址可能会不一样,这跟当时IP地址资源有关。

SSID

Service Set Identifier是指服务集标识。SSID技术可以将一个无线局域网分为几个需要不同身份验证的子网络,每一个子网络都需要独立的身份验证,只有通过身份验证的用户才可以进入相应的子网络,防止未被授权的用户进入本网络。

无线信道

信道,也称作通道或频段。无线信号是以某一频率传送数据的。2.4G频段的工作频率为2.4-2.4835GHz,这83.5MHz频带划分为13个信道,各信道中心频率相差5MHz,向上向下分别扩展11MHz,信道带宽22MHz。中国采用欧洲/ETSI标准,使用1-13信道。

频段带宽

20Mhz和40Mhz的区别,你可以想象成道路的宽度,宽度越宽当然同时能跑的数据越多,也就提高了速度。

20MHz对应的是65M带宽,穿透性相对较好,40MHz对应的是150M带宽,穿透性肯定不如20MHz 所以追求稳定的话就选择20MHz,近距离传输就可以选择40MHZ。

当然,无线网的“道路”是大家共享的,一共就这么宽(802.11 b/g/n的频带是 2.412Ghz ~ 2.472Ghz,一共60Mhz。像802.11a/n在中国可用的频带是5.745Ghz ~ 5.825Ghz,同样也是60Mhz),你占用的道路宽了,跑得数据多了,当然就更容易跟别人撞车,一旦撞车大家就都会慢下来,比你在窄路上走还要慢。

如图,原来挤一挤可以四个人同时用的,如果你用了40Mhz的话就只能两个人同时用了。所以哪个更好的问题和你多大的房子无关,最主要的是你附近有多少个人跟你一起上路的,用NetStumbler这种扫描软件可以很容易看清楚周围频带的占用情况,如果你附近没什么人用,那么恭喜你,用40Mhz来享受高速吧!如果周围“车辆”很多,那么你最好还是找一个车少点的“车道”,老老实实用20Mhz比较好。

NetStumbler

04年停止更新的软件,不支持我笔记本的网卡

Intel WIFI6 ax200 160MHz

11bgn mixed

无线协议: 11b..=网络速度运行在11b网络标准,11g..=网络速度运行在11g网络标准,11n..=网络速度运行在11n网络标准。

如果你不知道你的无线设备是什么级别,802.11b/g/n是最好的选择。如果只使用.11n,旧设备可能存在兼容性问题。当然,速度是支持N的最快方式,但是它必须与特定的设备相结合。

实际的情况是,无线局域网的实际传输速度只能达到产品标称最大传输速度的一半以下;比如802.11b理论最大速度为11M,通过笔者的测试,在无线网络环境较好的情况下,传输100MB的文件需要3分钟左右;而相同的环境,换为支持802.11g的产品,传输100MB的文件就只需要30秒左右。

150M的网络理论下载速率

150M 全写是 150Mbps,注意这里是小b,是位数。所以与MB的兆字节是不一样的,需要除8,加上一点损耗。150Mbps网络有15MB/s就不错了。

怎么判断网络是百兆还是千兆

  1. 通过路由器WAN口速率设置,10/100M自动协商

如果是有线PC的话,看网卡信息,如果连接速度是1G的就是千兆网络,如果100M 就是百兆。

第二种方法: 测试下载速度,如果下载速度能够达到12.5MB/s以上就是千兆(1000/8),反之就是百兆。

第三种方法: 看交换机上的速度灯,如果千兆灯亮就是千兆,百兆灯亮就是百兆。如图(绿灯千兆,黄灯百兆)

家里明显是加强的百兆网络。

全双工和半双工

区别是:1、全双工允许数据在两个方向上同时传输;2、半双工允许数据在两个方向上传输,但是同一时间数据只能在一个方向上传输,实际上是切换的单工。

同样是100M的链路,一条是全双工,另一条是半双工,如果两条链路上都进行单向通信的话,理论上是都可以达到100M的(注意:这里全双工也只有100M),但是如果两条链路都进行双向通信就不一样了,双向通信时,全双工的链路的吞吐量是200M(两个方向每个方向上都是100M),而半双工最大也只有100M。但是虽然全双工的最大吞吐量能够达到200M,但是他使用的最大带宽永远都是100M,你不可能将双向的200M变成单向的200M。

因此全双工的带宽=半双工的带宽,全双工的吞吐量=2×半双工的吞吐量。

WPA2-PSK

WPA/WPA2

WPA/WPA2是一种最安全的加密类型,不过由于此加密类型需要安装Radius服务器,因此,一般普通用户都用不到,只有企业用户为了无线加密更安全才会使用此种加密方式,在设备连接无线WIFI时需要Radius服务器认证,而且还需要输入Radius密码。

WPA-PSK/WPA2-PSK

WPA-PSK/WPA2-PSK是我们现在经常设置的加密类型,这种加密类型安全性能高,而且设置也相当简单,不过需要注意的是它有AES和TKIP两种加密算法。 1. TKIP:Temporal Key Integrity Protocol(临时密钥完整性协议),这是一种旧的加密标准。 2. AES:Advanced Encryption Standard(高级加密标准),安全性比 TKIP 好,推荐使用。

使用AES加密算法不仅安全性能更高,而且由于其采用的是最新技术,因此,在无线网络传输速率上面也要比TKIP更快。

CommView

软件首次运行时,会提示你安装一个特别的无线网卡驱动,这个驱动可以使你的无线网卡处在混杂模式,接收周围的任何无线报文。

软件启动时,无线网卡模式被改变,无线网络是无法使用的。

我虽然看不懂,但是我大受震撼。但是只能5分钟试运行

无线传输原理

比如,我在图书馆上网的时候,我的电脑并没有收到对面妹子的web请求包回复啊?无线数据包已经发送到你的无线网卡,但是你的网卡一看(主要受网卡驱动影响),不是我的请求数据包啊,于是丢弃了。

使用commview for wifi破解Windows无线网络WEP加密的密钥

需要进一步的研究学习

为什么comview里好多华为,是很多人开了手机热点吗?

Type – node type. Possible values are AP (for access points), STA (for stations in infrastructure mode) and AD HOC (for stations in ad hoc mode).

家庭网络改造

当前现状

  1. 套餐:公务员免费移动百兆套餐
  2. 网络设备:
  3. 光猫自带的wifi,最高只支持到wifi4 的2.4GHz
  4. 不支持ipv6的垃圾TP-link路由器

改进

  1. 将路由器更换为wifi6,直接跑满百兆(在学校里都能随便千兆的)

遇到的问题

暂无

开题缘由、总结、反思、吐槽~~

暑假回到家,把家里的WiFi弄一下

参考文献

https://www.zhihu.com/question/53878059

FTP

FTP简介

FTP是File Transfer Protocol(文件传输协议)的缩写,用来在两台计算机之间互相传送文件。相比于HTTP,FTP协议要复杂得多。复杂的原因,是因为FTP协议要用到两个TCP连接,一个是命令链路,用来在FTP客户端与服务器之间传递命令;另一个是数据链路,用来上传或下载数据。

主动与被动模式

FTP协议有两种工作方式:PORT方式和PASV方式,中文意思为主动式和被动式。

区别主要在于数据通道的建立方式:

  • 主动模式:服务器向客户端敲门,然后客户端开门
  • 在主动模式中,客户端向服务器发送一个随机端口号,服务器再用这个端口号和客户端建立数据通道。这样,服务器需要知道客户端的 IP 地址和端口号,并且能够穿透客户端的防火墙。
  • 如果通过代理上网的话,就不能用主动模式,因为服务器敲的是上网代理服务器的门,而不是敲客户端的门
  • 客户端也不是轻易就开门的,因为有防火墙阻挡,除非客户端开放大于1024的高端端口
  • 被动模式:客户端向服务器敲门,然后服务器开门
  • 在被动模式中,服务器向客户端发送一个随机端口号,客户端再用这个端口号和服务器建立数据通道。这样,客户端不需要公开自己的 IP 地址和端口号,并且只需要打开出站连接的防火墙。

ftp命令行登录

ftp ip
lftp user@site:port

常用命令

  1. 下载文件通常用get和mget这两条命令。
  2. 上传文件put和mput
  3. 断开连接bye

ftp空间

但是这个是当前目录的文件,不包括文件夹 1字节=1B,1024B=1KB

Ubuntu ftp服务器部署

vsftpd

  1. 安装
sudo apt install vsftpd # 安装
  1. 配置文件 /etc/vsftpd/vsftpd.conf
 local_enable=YES # 是否允许本地用户访问  
 local_root=/home/kaikai_ftp/ftpdir # 自定义上传根目录
 write_enable=YES # 允许用户修改文件权限
  1. vsftpd虚拟用户
  2. 运行
systemctl restart vsftpd.service
重启
sudo service vsftpd start
开机启动
sudo systemctl enable vsftpd
查看运行情况
sudo service vsftpd status

vsftpd虚拟用户

虚拟用户
  1. 虚拟用户,只对ftp有效的用户。这些用户不可以登录Linux系统,只可以登录ftp服务器。其实就是一个本地用户映射成多个只对ftp服务器有效的虚拟用户。虚拟用户可以有自己的ftp配置文件,因此通常利用虚拟用户来对ftp系统的不同用户制定不同的权限,以达到安全控制的目的。与虚拟用户有关的设置以guest_开头。
  2. 匿名用户,也就是不需要输入密码就可登录ftp服务器的用户,这个用户名通常是ftp或anonymous; 与匿名用户有关的设置多以 anon_选项开头。
  3. 本地用户,也就是你Linux系统上可登录到系统的用户,这些用户是在系统上实实在在存在的用户。通常会有自己的home,shell等。与本地用户有关的设置多以local_开头或包含local_的选项。

●所有虚拟用户会统一映射为一个指定的系统帐号:访问共享位置,即为此系统帐号的家目录

●各虚拟用户可被赋予不同的访问权限,通过匿名用户的权限控制参数进行指定

具体命令
  1. 创建用户数据库文件
vim /etc/vsftpd/vusers.txt
    ftp123
    ftp2333
  1. 文件需要被加密编码为hash格式奇数行为用户名,偶数行为密码
sudo apt-get install db-util # install db_load
sudo db_load -T -t hash -f vusers.txt vusers.db #该 db_load 实用程序可用于将文本文件加载到数据库中
chmod 600 vusers.db
  1. 创建用户和访问FTP目录
sudo useradd -d /data/ftproot -s /sbin/nologin -r vuser
    # -d, --home-dir HOME_DIR       home directory of the new account
    # -s, --shell SHELL             login shell of the new account
    # -r, --system                  create a system account
mkdir -pv /data/ftproot/upload #-pv 是没有父路径也会创建
setfacl -m u:vuser:rwx /data/ftproot/upload
    # set file access control lists
    # -m, --modify
#chmod a=rx /data/ftproot/  如果自动创建家目录,需要改权限
  1. 创建pam配置文件
vim /etc/pam.d/vsftpd.db
 auth required pam_userdb.so db=/etc/vsftpd/vusers
 account required pam_userdb.so db=/etc/vsftpd/vusers
  1. 指定pam配置文件
vim /etc/vsftpd/vsftpd.conf

pam_service_name=vsftpd.db
userlist_enable=YES

guest_enable=YES #所有系统用户都映射成guest用户
guest_username=vuser #配合上面选项才生效,指定guest用户
user_config_dir=/etc/vsftpd/vusers.d/  #虚拟用户设置独立的配置文件
write_enable=YES

anonymous_enable=NO # 匿名访问是否允许,默认不要开启
local_enable=YES # 是否允许本地用户访问  
local_root=/home/shaojiemike/ftpdir # 自定义上传根目录
虚拟用户设置独立的配置文件

指定各用户配置文件存放的路径

vim /etc/vsftpd/vsftpd.conf
user_config_dir=/etc/vsftpd/vusers.d/

创建各个用户的配置文件存放路径,配置文件的文件名需要与用户名一致。 没有独立配置文件的虚拟用户会遵守/etc/vsftpd/vsftpd.conf这个主配置文件的权限配置。

mkdir /etc/vsftpd/vusers.d/
cd /etc/vsftpd/vusers.d/
vim ftp123
    # 允许用户有自己的上传目录以及上传权限,添加这些参数以及值
    local_root=/tmp/vutest_d
    anon_upload_enable=YES
    anon_mkdir_write_enable=YES
    anon_other_write_enable=YES
    allow_writeable_chroot=YES

建立目录,更改目录的所有者与所属组

mkdir /tmp/vutest_d
chown vuser:vuser  /tmp/vutest_d   #还是那句话,用户能不能上传不仅与配置文件有关,还与目录是否有w权限有关,两个权限都开启才能正确上传。
chmod 755 upload

Linux-PAM 的配置文件

PAM 的各个模块一般存放在 /lib/security/ 或 /lib64/security/ 中,以动态库文件的形式存在,文件名格式一般为 pam_*.so。

PAM 的配置文件可以是 /etc/pam.conf 这一个文件,也可以是 /etc/pam.d/ 文件夹内的多个文件。如果 /etc/pam.d/ 这个文件夹存在,Linux-PAM 将自动忽略 /etc/pam.conf。

  1. /etc/pam.conf 类型的格式如下:
服务名称  工作类别  控制模式  模块路径  模块参数
  1. /etc/pam.d/ 类型的配置文件通常以每一个使用 PAM 的程序的名称来命令。比如 /etc/pam.d/su,/etc/pam.d/login 等等。还有些配置文件比较通用,经常被别的配置文件引用,也放在这个文件夹下,比如 /etc/pam.d/system-auth。这些文件的格式都保持一致:
工作类别  控制模式  模块路径  模块参数

需要进一步的研究学习

Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's capabilities.

遇到的问题

530 Login incorrect.
Login failed.
  1. 尝试改shell,但首先不是这个问题
cat /etc/shells #没有/sbin/nologin
sudo usermod -s /bin/bash vuser
cat /etc/passwd #shell改好了
  1. 查看报错 我以为我是修改错文件了,但是好像没怎么简单
  2. 添加
guest_enable=YES   # 开启虚拟用户
guest_username=vuser  # FTP虚拟用户对应的系统用户,即第四步添加的用户

报错 后来发现原因是,变量这一行不要加注释 guest_enable=YES # 开启虚拟用户 4. 只改pam的路径为pam.db 报错 这很明显是没有指定用户

实际问题

home.ustc.edu.cn

ftp 上传的内容几秒中之内被覆盖了。这是学校网站的保护机制吗?(我之前调试修改太多了?)

   ftp> get index.html
   local: index.html remote: index.html
   200 EPRT command successful. Consider using EPSV.
   150 Opening BINARY mode data connection for index.html (360991 bytes).
   226 File send OK.
   360991 bytes received in 0.01 secs (25.7474 MB/s)
   ftp> get index.html
   local: index.html remote: index.html
   200 EPRT command successful. Consider using EPSV.
   150 Opening BINARY mode data connection for index.html (16116 bytes).
   226 File send OK.
   16116 bytes received in 0.00 secs (15.3082 MB/s)

I try single command line put site/index.html index.html and after a minute get index.html get the old file.

My USTC homepage is blocked

ftp> ls
200 EPRT command successful. Consider using EPSV.
150 Here comes the directory listing.
drwxr-xr-x   46 0        0            4096 Oct 25 10:03 public_html.old
226 Directory send OK.
ftp> mkdir public_html
550 Create directory operation failed.
ftp> put jumpPage.html
local: jumpPage.html remote: jumpPage.html
200 EPRT command successful. Consider using EPSV.
553 Could not create file.

参考文献

https://www.jianshu.com/p/ac3e7009a764

https://blog.csdn.net/frank_ci/article/details/108847358

https://blog.csdn.net/enweitech/article/details/51330664

Home Network

ping、arp、tracert、route命令

tracert

https://zhuanlan.zhihu.com/p/504688650

ipv6

查看是否有ipv6

ipw.cn 查看是否有ipv6(手机热点是ipv6优先的)

如图,由于不支持,所以ping不了ipv6

D:\PowerShell\github\hugoMinos [main ≡ +1 ~4 -0 !]> ping 2001:da8:d800:112::23

Pinging 2001:da8:d800:112::23 with 32 bytes of data:
PING: transmit failed. General failure.
PING: transmit failed. General failure.
PING: transmit failed. General failure.

2001:da8:d800:112::23 的 Ping 统计信息:
    数据包: 已发送 = 3,已接收 = 0,丢失 = 3 (100% 丢失),

光猫,路由器修改ipv6

光猫背后账号,密码,和移动的网址http://192.168.1.1/

参考:https://www.luyouwang.net/8778.html

这网络界面根本改不了,G

这是普通用户账号密码,查询移动给的吉比特智能网关GM220-S的超级管理员

账号:CMCCAdmin
密码:aDm8H%MdA
感觉应该开启了ipv6的样子,难道是子路由没开?

原因是子路由普联TL-WR886N不支持ipv6

LAN1的T568B水晶头还只有4根: 网线8根线1236重要。

网线8根线一般只使用1、2、3、6编号的芯线传递数据,即1、2用于发送,3、6用于接收。

4578属于备用线路,1236有故障时自动切换4578,如果4578没有接好,导致的结果就是1236中的某一根出现问题时,因没有备用线路而断网。

NAT6

解决办法: 1. 首先换成小米的WIFI6的路由器 2. 打开ipv6的功能,由于家里暂时没有外网访问家庭设备的需求 1. 没有设置桥接 2. 采用了简单的NAT6来实现家庭ipv6上网 3. 虽然恩山的论坛说很慢,因ipv6地址更长,所以效率更低,速度更慢。,但是NAT6百兆还是能跑满的

获取pppoe 账号密码

备份config.bin后,用routerpassview工具打开,查找用户名,结果发现密码就是123456。我真是无语了(小潮🦅

意外之喜,我家竟然是“千兆网”

原本以为我家是爸爸法院送的移动网不会怎么样,结果直接插GM220-S的千兆口,竟然是非对等带宽的千兆网

但是弱电箱就埋了两根线,一根是到客厅的iptv的线,另一根是到主卧室的(但是水晶头里的线被剪断一半的,导致实际测速只有百兆的线。

临时处理:暂时用iptv的线当拉出来的网线。能达到300Mbps的WIFI-6

需要进一步的研究学习

暂无

遇到的问题

  1. 学校的服务器全部ping不通

没有登录网络的肯定ping不通

登录了ping不通的原因是,脚本默认是8号端口,改成0号教育网端口就行了。

D:\PowerShell> ping -r 9 -w 10000 222.195.72.114

Pinging 222.195.72.114 with 32 bytes of data:
Reply from 222.195.72.114: bytes=32 time=60ms TTL=60
    Route: 172.17.0.3 -> (局域网)
           202.38.73.217 -> (node5)
           202.38.96.189 -> (北京教育网)
           210.45.112.254 -> (合肥教育网)
           222.195.72.114 -> (snode2)
           222.195.72.114 -> 
           202.38.96.188 ->(北京教育网)
           202.38.73.254 ->(合肥教育网)
           172.17.0.1

  1. ipv6不知道是不是因为变化了,也连接不上

家里路由器不支持ipv6,所以连接不上

开题缘由、总结、反思、吐槽~~

参考文献

https://jingyan.baidu.com/article/ac6a9a5e47b4222b653eac95.html

OpenVPN in Docker

在接触wireguard之前,网络返校的方案是自己在有公网IP的机器上搭建OpenVPN。而使用docker比裸机配置OpenVPN方便多了。

OpenVPN Image

ARM

我們使用 kylemanna/docker-openvpn 來實作,因為 dockerhub 上只有 x86 image,如果是 arm 平台則需要自己 build(x86 可跳過)

clone repo 後,直接 build

$ git clone https://github.com/kylemanna/docker-openvpn
$ cd docker-openvpn
$ docker build -t kylemanna/openvpn -f Dockerfile.aarch64 .
如果發生找不到 aarch64/alpine:3.5 的錯誤,修改 Dockerfile 中的 base image 為
FROM alpine:3.15.4
或更新的 alpine 版本即可

相关的中文教程

http://blog.gdb.wiki/2020/03/19/Docker-OpenVPN%E9%95%9C%E5%83%8F%E9%85%8D%E7%BD%AE/#kylemanna-openvpn%E8%BF%99%E4%B8%AA%E9%95%9C%E5%83%8F%E5%B0%86%E5%A4%A7%E9%83%A8%E5%88%86%E7%9A%84%E4%B8%80%E9%94%AE%E5%8C%96%E8%87%AA%E5%8A%A8%E8%84%9A%E6%9C%AC%E8%BF%9B%E8%A1%8C%E6%95%B4%E5%90%88%EF%BC%8C%E9%80%9A%E8%BF%87docker-run%E4%B8%80%E6%AD%A5%E4%B8%80%E6%AD%A5%E8%BF%9B%E8%A1%8C%E9%85%8D%E7%BD%AE

https://koding.work/10-minutes-build-open-vpn-server/

https://taichunmin.idv.tw/blog/2018-05-23-docker-openvpn.html

Quick Start

以README为主

# shaojiemike @ node5 in ~ [23:53:42] C:125
$ export OVPN_DATA="ovpn-data-tsj"

# shaojiemike @ node5 in ~ [23:54:10]
$ docker volume create --name $OVPN_DATA
ovpn-data-example

# shaojiemike @ node5 in ~ [23:54:11]
$ docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://node5.xydustc.me
Unable to find image 'kylemanna/openvpn:latest' locally
latest: Pulling from kylemanna/openvpn
188c0c94c7c5: Pull complete
e470f824352c: Pull complete
d6ed0c7c142e: Pull complete
74586f3c5cd4: Pull complete
cb26244a2b2a: Pull complete
Digest: sha256:643531abb010a088f1e23a1c99d44f0bd417a3dbb483f809caf4396b5c9829a0
Status: Downloaded newer image for kylemanna/openvpn:latest
Processing PUSH Config: 'block-outside-dns'
Processing Route Config: '192.168.254.0/24'
Processing PUSH Config: 'dhcp-option DNS 8.8.8.8'
Processing PUSH Config: 'dhcp-option DNS 8.8.4.4'
Processing PUSH Config: 'comp-lzo no'
Successfully generated config
Cleaning up before Exit ...
CA(certificate authority.)的私钥密码
# shaojiemike @ node5 in ~ [23:55:47]
$ docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki

init-pki complete; you may now create a CA or requests.
Your newly created PKI dir is: /etc/openvpn/pki


Using SSL: openssl OpenSSL 1.1.1g  21 Apr 2020

Enter New CA Key Passphrase:
Re-Enter New CA Key Passphrase:
Generating RSA private key, 2048 bit long modulus (2 primes)
.........+++++
...................+++++
e is 65537 (0x010001)
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Common Name (eg: your user, host, or server name) [Easy-RSA CA]:tsj-node5

CA creation complete and you may now import and sign cert requests.
Your new CA certificate file for publishing is at:
/etc/openvpn/pki/ca.crt

Using SSL: openssl OpenSSL 1.1.1g  21 Apr 2020
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
......................+.......................+..........................................................+........................................................................................................+........................................+...................................................................................................................................+.....................................................................................................................+......................................................................................................................................................................................................................................+......++*++*++*++*

DH parameters of size 2048 created at /etc/openvpn/pki/dh.pem


Using SSL: openssl OpenSSL 1.1.1g  21 Apr 2020
Generating a RSA private key
.......................................+++++
.........................................+++++
writing new private key to '/etc/openvpn/pki/easy-rsa-73.EeNnaB/tmp.jhHaaF'
-----
Using configuration from /etc/openvpn/pki/easy-rsa-73.EeNnaB/tmp.LGnDjB
Enter pass phrase for /etc/openvpn/pki/private/ca.key:
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName            :ASN.1 12:'node5.xydustc.me'
Certificate is to be certified until Jan  1 15:58:37 2025 GMT (825 days)

Write out database with 1 new entries
Data Base Updated

Using SSL: openssl OpenSSL 1.1.1g  21 Apr 2020
Using configuration from /etc/openvpn/pki/easy-rsa-148.CDCEmf/tmp.iJCIGL
Enter pass phrase for /etc/openvpn/pki/private/ca.key:

An updated CRL has been created.

1194貌似有人用了

# shaojiemike @ node5 in ~ [0:02:06]
$ sudo lsof -i UDP:1194
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
openvpn 1834 nobody    6u  IPv4  56802      0t0  UDP node5:openvpn

 /usr/sbin/openvpn --status /run/openvpn-server/status-server.log --status-version 2 --suppress-timestamps --config server.conf

  sudo vim /etc/openvpn/server/server.conf

  改成7194等端口

# shaojiemike @ node5 in ~ [0:02:10]
$ sudo service openvpn status
 openvpn.service - OpenVPN service
     Loaded: loaded (/lib/systemd/system/openvpn.service; enabled; vendor preset: enabled)
     Active: active (exited) since Tue 2022-04-19 18:42:24 CST; 5 months 11 days ago
   Main PID: 1715 (code=exited, status=0/SUCCESS)
      Tasks: 0 (limit: 154181)
     Memory: 0B
     CGroup: /system.slice/openvpn.service

Apr 19 18:42:24 node5 systemd[1]: Starting OpenVPN service...
Apr 19 18:42:24 node5 systemd[1]: Finished OpenVPN service.

# shaojiemike @ node5 in ~ [0:15:49] C:125
$ sudo service openvpn stop

# shaojiemike @ node5 in ~ [0:16:30]
$ sudo kill -9 1834

在1195启动服务失败,还是1194

# shaojiemike @ node5 in ~ [0:16:46]
$ docker run -v $OVPN_DATA:/etc/openvpn -d -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
cb0f7e78f389f112c3c3b230d20d2b50818f6cf59eea2edfaa076c7e8fad7128

# shaojiemike @ node5 in ~ [0:06:01]
$ docker container list
CONTAINER ID   IMAGE                   COMMAND                  CREATED          STATUS                  PORTS                                                 NAMES
6c716b27b3f1   kylemanna/openvpn       "ovpn_run"               49 seconds ago   Up 48 seconds           1194/udp, 0.0.0.0:1195->1195/udp, :::1195->1195/udp   charming_zhukovsky

# 上面是错误的

# shaojiemike @ node5 in ~ [0:16:50]
$ docker ps
CONTAINER ID   IMAGE                   COMMAND                  CREATED              STATUS                  PORTS                                                 NAMES
cb0f7e78f389   kylemanna/openvpn       "ovpn_run"               About a minute ago   Up About a minute       0.0.0.0:1194->1194/udp, :::1194->1194/udp             pedantic_euler
产生客户端证书,和ovpn文件
# shaojiemike @ node5 in ~ [0:07:27] C:2
$ docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn easyrsa build-client-full tsj-node5-client nopass
Using SSL: openssl OpenSSL 1.1.1g  21 Apr 2020
Generating a RSA private key
...............+++++
...............................+++++
writing new private key to '/etc/openvpn/pki/easy-rsa-1.olaINa/tmp.MfohAO'
-----
Using configuration from /etc/openvpn/pki/easy-rsa-1.olaINa/tmp.EMkEHF
Enter pass phrase for /etc/openvpn/pki/private/ca.key:
139775495048520:error:28078065:UI routines:UI_set_result_ex:result too small:crypto/ui/ui_lib.c:905:You must type in 4 to 1023 characters
Enter pass phrase for /etc/openvpn/pki/private/ca.key:
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName            :ASN.1 12:'tsj-node5-client'
Certificate is to be certified until Jan  1 16:08:23 2025 GMT (825 days)

Write out database with 1 new entries
Data Base Updated


# shaojiemike @ node5 in ~ [0:08:24]
$ docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_getclient tsj-node5-client > tsj-node5-client.ovpn

# shaojiemike @ node5 in ~ [0:09:20]
$ ls tsj-node5-client.ovpn
tsj-node5-client.ovpn

还是不行,奇怪

解决办法

ping不通的原因是,脚本默认是8号端口,改成0号教育网端口就行了。

D:\PowerShell> ping -r 9 -w 10000 222.195.72.114

Pinging 222.195.72.114 with 32 bytes of data:
Reply from 222.195.72.114: bytes=32 time=60ms TTL=60
    Route: 172.17.0.3 -> (局域网)
           202.38.73.217 -> (node5)
           202.38.96.189 -> (北京教育网)
           210.45.112.254 -> (合肥教育网)
           222.195.72.114 -> (snode2)
           222.195.72.114 -> 
           202.38.96.188 ->(北京教育网)
           202.38.73.254 ->(合肥教育网)
           172.17.0.1

OpenVPN 3 linux client

apt install

First ensure that your apt supports the https transport:

   # apt install apt-transport-https
Install the OpenVPN repository key used by the OpenVPN 3 Linux packages
   # curl -x http://$proxy_addr:$proxy_http_port -fsSL https://swupdate.openvpn.net/repos/openvpn-repo-pkg-key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/openvpn-repo-pkg-keyring.gpg
Then you need to install the proper repository. Replace $DISTRO with the release name depending on your Debian/Ubuntu distribution.
   # curl -x http://$proxy_addr:$proxy_http_port -fsSL https://swupdate.openvpn.net/community/openvpn3/repos/openvpn3-$DISTRO.list >/etc/apt/sources.list.d/openvpn3.list
   # apt update
Supported distributions:

Distribution| Release| Release name ($DISTRO)| Architecture| DCO support |---| ---| ---| ---| ---| Ubuntu| 20.04| focal |amd64, arm64 |yes Ubuntu| 21.10| impish| amd64, arm64| yes Ubuntu| 22.04| jammy| amd64, arm64|yes

And finally the openvpn3 package can be installed

   # apt install openvpn3
apt需要代理看 apt-get install proxy

openvpn3使用

要提前保留ipv6, 没有设置“流量走当前机器”ssh会断联

Once you’ve moved the file to your Linux system, you can import it.

openvpn3 config-import --config ${client.ovpn}
Configuration imported.  Configuration path: /net/openvpn/v3/configuration/1f475d5cx8d2fx4ef5x8feex25f2871f2642
You can start a new VPN session:
openvpn3 session-start --config ${client.ovpn}
Configuration imported.  Configuration path: /net/openvpn/v3/configuration/1f475d5cx8d2fx4ef5x8feex25f2871f2642
You can manage a running VPN session:
openvpn3 sessions-list
-----------------------------------------------------------------------------
        Path: /net/openvpn/v3/sessions/f83c75e4sd56cs4b27s85bcsc5c6e3ce074e
     Created: Thu Oct  6 20:37:29 2022                  PID: 1034954
       Owner: shaojiemike                            Device: tun1
 Config name: node5-client.ovpn
Session name: snode6.swangeese.fun
      Status: Connection, Client connected
-----------------------------------------------------------------------------

$ openvpn3 session-manage
session-manage: ** ERROR ** One of --pause, --resume, --restart, --disconnect, --cleanup or --log-level must be present

$ openvpn3 session-manage --pause -c node5-client.ovpn
Initiated session pause: /net/openvpn/v3/sessions/f83c75e4sd56cs4b27s85bcsc5c6e3ce074e

需要进一步的研究学习

netplan 的 rule from to table

ip route

ip rule指令学习

iptables

遇到的问题

暂无

开题缘由、总结、反思、吐槽~~

参考文献

基于kylemanna/docker-openvpn

https://openvpn.net/vpn-server-resources/connecting-to-access-server-with-linux/

SSHForward

导言

服务器没网,姜师兄说可以ssh转发网络请求到本地windows

四类ssh转发

SSH 端口转发自然需要 SSH 连接,而SSH 连接是有方向的,从 SSH Client 到 SSH Server 。

而我们所要访问的应用也是有方向的,应用连接的方向也是从应用的 Client 端连接到应用的 Server 端。比如需要我们要访问Internet上的Web站点时,Http应用的方向就是从我们自己这台主机(Client)到远处的Web Server。

本地转发Local Forward

如果SSH连接和应用的连接这两个连接的方向一致,那我们就说它是本地转发。

ssh -L [bind_address:]port:host:hostport <SSH hostname>
ssh -L 3333:127.0.0.1:2333 -vN -f -l shaojiemike 222.195.72.218
debug1: Local connections to LOCALHOST:3333 forwarded to remote address(222.195.72.218) 127.0.0.1:2333

本地转发在本地这台机器上监听一个端口,然后所有访问这个端口的数据都会通过ssh 隧道传输到远端的对应端口上。命令中的 host 和 <SSH hostname> 可以是不同的主机。

远程转发Remote Forward

如果SSH连接和应用的连接这两个连接的方向不同,那我们就说它是远程转发。

ssh -R [bind_address:]port:host:hostport <SSH hostname>

远程转发与本地转发正好相反,打开ssh隧道以后,在远端服务器监听一个端口,所有访问远端服务器指定端口都会通过隧道传输到本地的对应端口上,下面是例子。

动态转发

  • TODO

X转发

  • TODO

实用参数

-C:压缩数据传输。
-f :后台认证用户/密码,通常和-N连用,不用登录到远程主机。
-N :不执行脚本或命令,通常与-f连用。
-g :在-L/-R/-D参数中,允许远程主机连接到建立的转发的端口,如果不加这个参数,只允许本地主机建立连接。
-f      Requests ssh to go to background just before command execution.  This is useful if ssh is going to ask for passwords or
             passphrases, but the user wants it in the background.  This implies -n.  The recommended way to start X11 programs at a remote
             site is with something like ssh -f host xterm.

             If the ExitOnForwardFailure configuration option is set to "yes", then a client started with -f will wait for all remote port
             forwards to be successfully established before placing itself in the background.

常见例子

将发往本机的80端口访问转发到174.139.9.66的8080端口

ssh -C -f -N -g -L 80:174.139.9.66:8080 [email protected]

将发往174.139.9.66的8080访问转发到本机的80端口

ssh -C -f -N -g -R 80:174.139.9.66:8080 [email protected]

使用远程管理服务器上的MySQL

ssh -C -f -N -g -L 80:174.139.9.66:8080 [email protected]

一次同时映射多个端口

ssh -L 8888:www.host.com:80 -L 110:mail.host.com:110 -L    25:mail.host.com:25 user@host -N  

反向隧道技术:节假日需要回公司加班。但是公司是内网,使用NAT,所以没办法连回去。

  1. 先在公司机器(LAN_ip)上执行
    ssh -NfR 2222:localhost:22 home_ip
    
    -R : 建立反向连接 将 home_ip port转发
  2. 然后到home_ip上面 ssh localhost -p 2222

端口转发:本机不允许访问www.xxx.com这个网站,但是远程主机(remote_ip)可以。

ssh -f -N -L 31609:www.xxx.com:80 user@remote_ip

现在我们就可以在本地打开 http://localhost:31609 访问www.xxx.com了。

SOCKS代理:本机不允许访问某些网站,但是远程主机(remote_ip)可以,并且公司没有组织你连接remote_ip。

ssh -NfD 8888 user@remote_ip

现在在浏览器socks 5 proxy设置为localhost:8888,所有之前无法访问的网站现在都可以访问了。

假设本地主机A提供了HTTP服务,主机B无网络

ssh -fNgR 80:localhost:80 root@host-B

通过访问 http://host-B 来访问主机A上的HTTP服务了。

如果没有主机B的root账号,则只能远程转发到1024以后的端口号

ssh -fNgR 8080:localhost:80 lige@host-B

通过访问http://host-B:8080 来访问主机A上的HTTP服务

假设本地主机A无网络,主机B提供了HTTP服务

但是由于怕防火墙屏蔽,而不想直接访问

ssh -fNgL 80:localhost:80 root@host-B

ssh_config设置技巧

客户端

.ssh/config修改

Host *
    ControlPersist yes
    ControlMaster auto
    ControlPath /tmp/sshcontrol-%C
    ControlPersist 1d
    # 以上四条配合使用,实现多条ssh连接共享,而且保持1天内ssh存在。再次执行ssh命令几乎秒连
    TCPKeepAlive=yes
    # 发送空TCP包来保持连接,但是可能被防火墙过滤
    ServerAliveInterval 30
    # 表示每隔多少秒(30秒),从客户端向服务器发送一次心跳(alive检测)
    # 心跳具体格式: debug1: client_input_global_request: rtype [email protected] want_reply 1
    ServerAliveCountMax 240 
    # 表示服务端多少次(240次)心跳无响应后, 客户端才会认为与服务器到SSH链接已经断开,然后断开连接。

    Port 443

Host *
   ForwardAgent yes
   # 可以讓本地的 SSH Key 在遠端 Server 上進行轉送,也就是经过跳板机Server1,使用本地key访问Server2,不用把key传到Server1上导致泄露
   # 虽然Server1不会获得key,但是可以使用key。所以该选项不宜用于Host *,应该只添加您信任的服务器以及打算用于代理转发的服务器。
   # 注意跳板机需要设置允许代理转发, /etc/ssh/sshd_config 将AllowAgentForwarding的值设置为yes, 并重启服务
   AddKeysToAgent yes
   ForwardX11 yes
   ForwardX11Trusted yes
   Compression yes
   # 压缩,加快数据传输速度

服务器端

更改ssh服务器的配置文件/etc/ssh/sshd_config

ClientAliveInterval 60
# 默认是0,不发送
ClientAliveCountMax 3

原理同上 重启ssh服务以使配置生效

systemctl restart sshd

服务器端如何将端口绑定到外部地址上

我们可以把这个映射的端口绑定在0.0.0.0的接口上,方法是加上参数-b 0.0.0.0。

同时修改SSH服务器端 /etc/sshd_configGatewayPorts noGatewayPorts yes来打开它。

自动重连/保持长时间连接

Host *
  ServerAliveInterval 60

检查隧道状态

  1. netstat
  2. ps
  3. autossh

实践

服务器网站端口转发到本地

ssh -L 6006:127.0.0.1:6006 -N -f -l acsacom snode6.swangeese.fun

本地网络代理到服务器

ssh -fNgR 7333:127.0.0.1:7890 [email protected]
ssh -fNgR 7333:127.0.0.1:80 [email protected]
  • 7333数字不要太小,以免冲突。
  • 7890是本地clash端口,80也可以。
服务器git下载设置代理端口
export http_proxy=http://127.0.0.1:7333
# wget 正常使用
export all_proxy=socks5://127.0.0.1:7333
# git 正常使用
unset http_proxy
unset all_proxy

特定软件也需要设置代理

git config --global https.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'

git config --global --unset http.proxy
git config --global --unset https.proxy
mac上转发失败

首先看看Windows上的输出

Mac的错误

在完成windows所有输出后,

  1. 首先调用了shell
  2. 错误
debug1: Remote: Forwarding listen address "localhost" overridden by server GatewayPorts
debug1: remote forward failure for: listen 7890, connect 127.0.0.1:7890
Warning: remote port forwarding failed for listen port 7890

猜测应该是已经端口占用了

netstat -nat |grep -i '7233'

解决办法一:换端口

首先,可以选择换端口,换成 7233

sudo lsof -i TCP:7233
1. 进程验证 2. wget验证 3. curl验证(原本会走WLT)

redirecting to http://wlt.ustc.edu.cn

解决办法二:Kill掉相关进程
sudo lsof -i TCP:7890
sudo kill -9 process_id_1 process_id_2 process_id_3
sudo ps -ef | grep 'nc -X' | grep -v grep | awk '{print $2}' | sudo xargs -r kill -9
sudo lsof -i TCP:7233 |grep shaojiemike| awk '{print $2}'|sudo xargs -r kill -9

  • FD: File Descriptor number of
  • 不敢kill师兄的,然后发现并没有用,寄。kill掉师兄的之后就行了,嘻嘻~~ 师兄不要怪我

参考文献

http://blog.sina.com.cn/s/blog_704836f40100lwxh.html

https://blog.csdn.net/xyyangkun/article/details/7025854?utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

Tcpdump & wireshark

命令行查看当前机器公网ip

> curl myip.ipip.net
当前 IP117.136.101.72  来自于中国 安徽   移动

检测机器端口开放

# 网页服务直接下载检查内容
wget 4.shaojiemike.top:28096
# -z 选项指示 nc 仅扫描打开的端口,而不发送任何数据,并且 -v 用于获取更多详细信息。
nc -z -v 4.shaojiemike.top 28096
或者扫描指定端口
# IPV6 也行
$ nmap -6 -p 8096 2001:da8:d800:611:5464:f7ab:9560:a646
Starting Nmap 7.80 ( https://nmap.org ) at 2023-01-04 19:33 CST
Nmap scan report for 2001:da8:d800:611:5464:f7ab:9560:a646
Host is up (0.00099s latency).

PORT     STATE SERVICE
8096/tcp open  unknown

Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds

$ nmap -p 28096 4.shaojiemike.top
Starting Nmap 7.80 ( https://nmap.org ) at 2023-01-04 19:19 CST
Nmap scan report for 4.shaojiemike.top (114.214.181.97)
Host is up (0.0011s latency).

PORT      STATE SERVICE
28096/tcp open  unknown

Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds
全部端口,但是会很慢。50分钟
sudo nmap -sT -p- 4.shaojiemike.top

wireshark

显示过滤

上方的过滤窗口

tcp.port==80&&(ip.dst==192.168.1.2||ip.dst==192.168.1.3)

ip.addr ==192.168.1.1 //显示所有目标或源地址是192.168.1.1的数据包
eth.addr== 80:f6:2e:ce:3f:00 //根据MAC地址过滤,详见“wireshark过滤MAC地址/物理地址”
tcp.port==23

捕捉过滤

抓包前在capture option中设置,仅捕获符合条件的包,可以避免产生较大的捕获文件和内存占用,但不能完整的复现测试时的网络环境。

host 192.168.1.1 //抓取192.168.1.1 收到和发出的所有数据包
src host 192.168.1.1 //源地址,192.168.1.1发出的所有数据包
dst host 192.168.1.1 //目标地址,192.168.1.1收到的所有数据包

color 含义

tcpdump

传统命令行抓包工具

常用参数

注意过滤规则间的and

  1. -nn :
  2. 单个 n 表示不解析域名,直接显示 IP;
  3. 两个 n 表示不解析域名和端口。
  4. 方便查看 IP 和端口号,
  5. 不需要域名解析会非常高效。
  6. -i 指定网卡 -D查看网卡
  7. -v-vv-vvv 来显示更多的详细信息
  8. port 80 抓取 80 端口上的流量,通常是 HTTP。在前面加src,dst限定词
  9. tcpudmp -i eth0 -n arp host 192.168.199 抓取192.168.199.* 网段的arp协议包,arp可以换为tcp,udp等。
  10. -A,-X,-xx会逐渐显示包内容更多信息
  11. -e : 显示数据链路层信息。
  12. 默认情况下 tcpdump 不会显示数据链路层信息,使用 -e 选项可以显示源和目的 MAC 地址,以及 VLAN tag 信息。

输出说明

192.168.1.106.56166 > 124.192.132.54.80
  1. ip 是 192.168.1.106,源端口是 56166,
  2. 目的地址是 124.192.132.54,目的端口是 80。
  3. > 符号代表数据的方向。

Flags

常见的三次握手 TCP 报文的 Flags:

[S] : SYN(开始连接)
[.] : 没有 Flag
[P] : PSH(推送数据)
[F] : FIN (结束连接)
[R] : RST(重置连接)

常见用途

  1. 根据目的IP,筛选网络经过的网卡和端口
  2. 能抓各种协议的包比如ping,ssh

案例分析

curl --trace-ascii - www.github.com

github ip 为 20.205.243.166

ifconfig显示 ibs5的网卡有21TB的带宽上限,肯定是IB卡了。

sudo tcpdump -i ibs5 '((tcp) and (host 20.205.243.166))'
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ibs5, link-type LINUX_SLL (Linux cooked v1), capture size 262144 bytes
15:53:53.848619 IP snode0.59878 > 20.205.243.166.http: Flags [S], seq 879685062, win 64128, options [mss 2004,sackOK,TS val 4096492456 ecr 0,nop,wscale 7], length 0
15:53:53.952705 IP 20.205.243.166.http > snode0.59878: Flags [S.], seq 1917452372, ack 879685063, win 65535, options [mss 1436,sackOK,TS val 1127310087 ecr 4096492456,nop,wscale 10], length 0
15:53:53.952728 IP snode0.59878 > 20.205.243.166.http: Flags [.], ack 1, win 501, options [nop,nop,TS val 4096492560 ecr 1127310087], length 0
15:53:53.953208 IP snode0.59878 > 20.205.243.166.http: Flags [P.], seq 1:79, ack 1, win 501, options [nop,nop,TS val 4096492561 ecr 1127310087], length 78: HTTP: GET / HTTP/1.1
15:53:54.058654 IP 20.205.243.166.http > snode0.59878: Flags [P.], seq 1:89, ack 79, win 64, options [nop,nop,TS val 1127310193 ecr 4096492561], length 88: HTTP: HTTP/1.1 301 Moved Permanently
15:53:54.058668 IP snode0.59878 > 20.205.243.166.http: Flags [.], ack 89, win 501, options [nop,nop,TS val 4096492666 ecr 1127310193], length 0
15:53:54.059092 IP snode0.59878 > 20.205.243.166.http: Flags [F.], seq 79, ack 89, win 501, options [nop,nop,TS val 4096492667 ecr 1127310193], length 0
15:53:54.162608 IP 20.205.243.166.http > snode0.59878: Flags [F.], seq 89, ack 80, win 64, options [nop,nop,TS val 1127310297 ecr 4096492667], length 0
$ sudo tcpdump -i ibs5 -nn -vvv -e '((port 80) and (tcp) and (host 20.205.243.166))'                                                                                                                                                 tcpdump: listening on ibs5, link-type LINUX_SLL (Linux cooked v1), capture size 262144 bytes
16:09:38.743478 Out ethertype IPv4 (0x0800), length 76: (tos 0x0, ttl 64, id 15215, offset 0, flags [DF], proto TCP (6), length 60)
    10.1.13.50.38376 > 20.205.243.166.80: Flags [S], cksum 0x1fd5 (incorrect -> 0x98b6), seq 1489092902, win 64128, options [mss 2004,sackOK,TS val 4097437351 ecr 0,nop,wscale 7], length 0
16:09:38.848164  In ethertype IPv4 (0x0800), length 76: (tos 0x0, ttl 48, id 0, offset 0, flags [DF], proto TCP (6), length 60)
    20.205.243.166.80 > 10.1.13.50.38376: Flags [S.], cksum 0x69ba (correct), seq 3753100548, ack 1489092903, win 65535, options [mss 1436,sackOK,TS val 3712395681 ecr 4097437351,nop,wscale 10], length 0
16:09:38.848212 Out ethertype IPv4 (0x0800), length 68: (tos 0x0, ttl 64, id 15216, offset 0, flags [DF], proto TCP (6), length 52)
    10.1.13.50.38376 > 20.205.243.166.80: Flags [.], cksum 0x1fcd (incorrect -> 0x9613), seq 1, ack 1, win 501, options [nop,nop,TS val 4097437456 ecr 3712395681], length 0
16:09:38.848318 Out ethertype IPv4 (0x0800), length 146: (tos 0x0, ttl 64, id 15217, offset 0, flags [DF], proto TCP (6), length 130)
    10.1.13.50.38376 > 20.205.243.166.80: Flags [P.], cksum 0x201b (incorrect -> 0x9f0a), seq 1:79, ack 1, win 501, options [nop,nop,TS val 4097437456 ecr 3712395681], length 78: HTTP, length: 78
        GET / HTTP/1.1
        Host: www.github.com
        User-Agent: curl/7.68.0
        Accept: */*

16:09:38.954152  In ethertype IPv4 (0x0800), length 156: (tos 0x0, ttl 48, id 45056, offset 0, flags [DF], proto TCP (6), length 140)
    20.205.243.166.80 > 10.1.13.50.38376: Flags [P.], cksum 0x024d (correct), seq 1:89, ack 79, win 64, options [nop,nop,TS val 3712395786 ecr 4097437456], length 88: HTTP, length: 88
        HTTP/1.1 301 Moved Permanently
        Content-Length: 0
        Location: https://www.github.com/

16:09:38.954207 Out ethertype IPv4 (0x0800), length 68: (tos 0x0, ttl 64, id 15218, offset 0, flags [DF], proto TCP (6), length 52)
    10.1.13.50.38376 > 20.205.243.166.80: Flags [.], cksum 0x1fcd (incorrect -> 0x949a), seq 79, ack 89, win 501, options [nop,nop,TS val 4097437562 ecr 3712395786], length 0
16:09:38.954884 Out ethertype IPv4 (0x0800), length 68: (tos 0x0, ttl 64, id 15219, offset 0, flags [DF], proto TCP (6), length 52)
    10.1.13.50.38376 > 20.205.243.166.80: Flags [F.], cksum 0x1fcd (incorrect -> 0x9498), seq 79, ack 89, win 501, options [nop,nop,TS val 4097437563 ecr 3712395786], length 0
16:09:39.060177  In ethertype IPv4 (0x0800), length 68: (tos 0x0, ttl 48, id 45057, offset 0, flags [DF], proto TCP (6), length 52)
    20.205.243.166.80 > 10.1.13.50.38376: Flags [F.], cksum 0x95e2 (correct), seq 89, ack 80, win 64, options [nop,nop,TS val 3712395892 ecr 4097437563], length 0
16:09:39.060221 Out ethertype IPv4 (0x0800), length 68: (tos 0x0, ttl 64, id 15220, offset 0, flags [DF], proto TCP (6), length 52)
    10.1.13.50.38376 > 20.205.243.166.80: Flags [.], cksum 0x1fcd (incorrect -> 0x93c4), seq 80, ack 90, win 501, options [nop,nop,TS val 4097437668 ecr 3712395892], length 0
16:09:46.177269 Out ethertype IPv4 (0x0800), length 76: (tos 0x0, ttl 64, id 38621, offset 0, flags [DF], proto TCP (6), length 60)

snode0 ip 是 10.1.13.50

traceroute

mtr = traceroute+ping

$ traceroute www.baid.com
traceroute to www.baidu.com (182.61.200.6), 30 hops max, 60 byte packets                                                                                                                                                           
1  acsa-nfs (10.1.13.1)  0.179 ms  0.180 ms  0.147 ms                                                                                                                                                                            
2  192.168.252.1 (192.168.252.1)  2.016 ms  1.954 ms  1.956 ms                                                                                                                                                                   
3  202.38.75.254 (202.38.75.254)  4.942 ms  3.941 ms  4.866 ms   

traceroute命令用于显示数据包到主机间的路径。

NETWORKMANAGER 管理

# shaojiemike @ snode0 in /etc/NetworkManager [16:49:55]
$ nmcli general status
STATE         CONNECTIVITY  WIFI-HW  WIFI     WWAN-HW  WWAN
disconnected  unknown       enabled  enabled  enabled  enabled

# shaojiemike @ snode0 in /etc/NetworkManager [16:50:40]
$ nmcli connection show
NAME                     UUID                                  TYPE        DEVICE
InfiniBand connection 1  7edf4eea-0591-48ba-868a-e66e8cb720ce  infiniband  --

好像之前使用过的样子。

# shaojiemike @ snode0 in /etc/NetworkManager [16:56:36] C:127
$ service network-manager status
● NetworkManager.service - Network Manager
     Loaded: loaded (/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-03-14 11:52:06 CST; 1 months 10 days ago
       Docs: man:NetworkManager(8)
   Main PID: 1339 (NetworkManager)
      Tasks: 3 (limit: 154500)
     Memory: 12.0M
     CGroup: /system.slice/NetworkManager.service
             └─1339 /usr/sbin/NetworkManager --no-daemon

Warning: some journal files were not opened due to insufficient permissions.

应该是这个 Secure site-to-site connection with Linux IPsec VPN 来设置的

需要进一步的研究学习

暂无

遇到的问题

暂无

开题缘由、总结、反思、吐槽~~

FJW说所有网络都是通过NFS一起出去的

参考文献