是否可以设置 Linux 系统使其提供超过 65,535 个端口?目的是让超过 65k 个守护进程在给定的系统上监听。
显然有端口正在使用,因此由于这些原因这是不可能的,因此将其视为尝试了解 TCP 在执行此类操作时会受到限制的地方的理论练习。
我有一台电脑:
Linux superhost 3.2.0-4-amd64 #1 SMP Debian 3.2.60-1+deb7u3 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
它在所有接口上的端口 80 上运行 Apache,并且它没有出现在 中netstat -planA inet,但意外地可以在 中找到netstat -planA inet6:
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 :::5672 :::* LISTEN 2402/beam.smp
tcp6 0 0 :::111 :::* LISTEN 1825/rpcbind
tcp6 0 0 :::9200 :::* LISTEN 2235/java
tcp6 0 0 :::80 :::* LISTEN 2533/apache2
tcp6 0 0 :::34611 :::* LISTEN 1856/rpc.statd
tcp6 0 0 :::9300 :::* …Run Code Online (Sandbox Code Playgroud) 我有一个系统,它有两个不同 IP 地址的网络接口,它们都在公共地址范围内(尽管在第一个的情况下通过 NAT)并且它们都有不同的网关。(长话短说,用于测试目的)
现在的问题是,如果我尝试 ping 第二个接口上的地址,默认路由会通过第一个接口指出 - 并且永远不会正确到达。
是否可以确保响应始终通过相同的网络接口(并具有相同的源 IP)发出?如果是这样,如何?
我有一个带有两个 NIC 的系统。这台机器和一些随附的设备将被移动并连接到不同的局域网,有时它会使用拨号上网。
eth0:
- 10.x.x.x address space
- no internet gateway
- only a few devices
eth1 (when used):
- 172.16.x.x or 192.168.x.x or other address spaces
- access to the gateway from LAN to internet
ppp0 (when used):
- internet access through dialup using KPPP
Run Code Online (Sandbox Code Playgroud)
我正在使用 ifconfig 来启动或关闭接口(除了由 KPPP 处理的 ppp0)。
如果我首先启动 eth1,它会从其 DHCP 获取地址并获取网关,然后将其添加到路由中,因此访问 LAN 和 Internet 没有问题。
如果我首先或第二次启动 eth0,它会获取其地址并将默认网关设置在其地址空间内(在 10.xxx 范围内)。如果我先打开 eth0,然后再打开 eth1,默认网关仍然保持在 10.xxx 范围内。
所以无论我做什么,eth0 都会覆盖 eth1 并在路由中“声明”网关。
有什么方法可以阻止 eth0 声明网关,或者确保 eth1(如果是第二个)使用它的网关?或者我可以以某种方式优先考虑应该使用哪个接口的网关而不是其他接口?
我基本上想确保使用 eth1 的默认地址空间网关,如果它处于活动状态,如果不是,则使用 …
我的一个 docker 容器在端口 8500 上公开了一个 HTTP 接口,该接口映射到主机端口 8500。它没有启用 IPv6。这仍然意味着,我应该能够在 localhost:8500 上访问它。IPv6 是首选,因此我最终收到了对 [::1]:8500 的请求。这个被卡住了,它永远不会回来。
用 curl 重现这个,这个命令卡住了:
curl -g -6 "http://[::1]:8500"
Run Code Online (Sandbox Code Playgroud)
curl 的 --verbose 选项没有显示任何内容, --ascii-trace 也没有。同时,对 IPv4 的 localhost 的请求成功:
curl http://127.0.0.1:8500
Run Code Online (Sandbox Code Playgroud)
给我预期的 HTML。如果我在环回上运行 IPv4 HTTP 服务器,使用
python -m SimpleHTTPServer 4001
Run Code Online (Sandbox Code Playgroud)
然后我为 IPv4 的本地主机获得了很多 HTML
curl http://127.1:4001
Run Code Online (Sandbox Code Playgroud)
以及 IPv6 的正确连接失败:
curl -g -6 "http://[::1]:4001"
curl: (7) Failed to connect to ::1 port 4001: Connection refused
Run Code Online (Sandbox Code Playgroud)
注意事项:Docker 1.7.1。容器未启用IPv6 ,因此没有 IPv6 iptable 规则。(ip6tables -v -L 什么也没给)
我的问题是:为什么请求会卡住,做什么?
我们可以使用语法${var##pattern}和${var%%pattern}提取 IPv4 地址的最后和第一部分:
IP=109.96.77.15
echo IP: $IP
echo 'Extract the first section using ${var%%pattern}: ' ${IP%%.*}
echo 'Extract the last section using ${var##pattern}: ' ${IP##*.}
Run Code Online (Sandbox Code Playgroud)
我们如何使用参数扩展提取 IPv4 地址的第二或第三部分?
这是我的解决方案:我使用一个数组并更改 IFS 变量。
:~/bin$ IP=109.96.77.15
:~/bin$ IFS=. read -a ArrIP<<<"$IP"
:~/bin$ echo ${ArrIP[1]}
96
:~/bin$ printf "%s\n" "${ArrIP[@]}"
109
96
77
15
Run Code Online (Sandbox Code Playgroud)
此外,我已经写了使用一些解决方案awk,sed以及cut命令。
现在,我的问题是:是否有基于不使用数组和 IFS 更改的参数扩展的更简单的解决方案?
我尝试在 CentOS 6.2 上配置静态 IPv4 和 IPv6 配置。
下面的配置完美地工作:
# ifconfig eth0 x.x.x.x/29
# route add defalt gw x.x.x.y
# ip addr add dev eth0 XXXX:C810:3001:D00::3/56
# ip -6 route add default XXXX:C810:3001:D00::1
Run Code Online (Sandbox Code Playgroud)
但是,我想在重新启动后保留此配置。
于是我做了如下配置:
启用 IPv6
[root@test network-scripts]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=test.net
NETWORKING_IPV6=yes
Run Code Online (Sandbox Code Playgroud)
接口配置
[root@test network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="static"
ONBOOT="yes"
HWADDR="2C:C3:AC:A8:C3:3E"
IPADDR=x.x.x.x
GATEWAY=x.x.x.x
NETMASK=255.255.255.248
TYPE=Ethernet
IPV6INIT=yes
IPV6ADDR=XXXX:C810:3001:D00::3/56
IPV6_DEFAULTGW=XXXX:C810:3001:D00::1
DNS1=208.67.222.222
DNS2=208.67.220.220
# Only DNS{1,2} according to /usr/share/doc/initscripts-9.03.27/sysconfig.txt
# DNS3=2620:0:ccc::2
# DNS4=2620:0:ccD::2
Run Code Online (Sandbox Code Playgroud)
重启网络
[root@test network-scripts]# service network restart
Arrêt de …Run Code Online (Sandbox Code Playgroud) 我有两台机器通过 CAT6 电缆连接到本地 IPv4 链路中。有没有办法host1确定我host2的 IPv4 地址?
我在运行内核 3.2.0-34-generic 的 Debian 衍生版本上。
我必须在我的机器上设置一个 FTP 服务器。我已经使用以下命令安装了 vsftpd:
sudo apt-get install vsftpd
Run Code Online (Sandbox Code Playgroud)
然后我编辑vsftpd.conf了位置中的配置文件/etc。该文件包含:
#Set the server to run in standalone mode
listen=YES
#Enable anonymous access
local_enable=NO
anonymous_enable=YES
#Disable write access
write_enable=NO
#Set root directory for anon connections
anon_root=/var/ftp
#Limit retrieval rate
anon_max_rate=2048000
#Enable logging user login and file transfers. /var/log/vsftpd.log
xferlog_enable=YES
#Set interface and port
listen_address=192.120.43.250
listen_port=21
Run Code Online (Sandbox Code Playgroud)
IP 地址 192.120.43.250 是我服务器的 eth0。当我运行命令时
sudo vsftpd /etc/vsftpd.conf
Run Code Online (Sandbox Code Playgroud)
我收到错误:
500 OOPS: could not bind listening IPv4 socket
Run Code Online (Sandbox Code Playgroud)
要检查端口 21 上正在运行的内容,我运行了以下命令:
sudo netstat -tulpn …Run Code Online (Sandbox Code Playgroud) 在服务器上wget-1.16需要 8 分钟才能完成:
$ wget http://http.debian.net/debian/dists/stable/Release -O -
--2017-06-12 23:44:40-- http://http.debian.net/debian/dists/stable/Release [4693/5569]
Resolving http.debian.net (http.debian.net)... 2001:4f8:1:c::15, 2605:bc80:3010:b00:0:deb:166:202, 2001:610:1908:b000::148:14, ...
Connecting to http.debian.net (http.debian.net)|2001:4f8:1:c::15|:80... failed: Connection timed out.
Connecting to http.debian.net (http.debian.net)|2605:bc80:3010:b00:0:deb:166:202|:80... failed: Connection timed out.
Connecting to http.debian.net (http.debian.net)|2001:610:1908:b000::148:14|:80... failed: Connection timed out.
Connecting to http.debian.net (http.debian.net)|140.211.166.202|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://cdn-fastly.deb.debian.org/debian/dists/stable/Release [following]
--2017-06-12 23:51:02-- http://cdn-fastly.deb.debian.org/debian/dists/stable/Release
Resolving cdn-fastly.deb.debian.org (cdn-fastly.deb.debian.org)... 2a04:4e42:3::204, 151.101.12.204
Connecting to cdn-fastly.deb.debian.org (cdn-fastly.deb.debian.org)|2a04:4e42:3::204|:80... failed: Connection timed out.
Connecting to cdn-fastly.deb.debian.org (cdn-fastly.deb.debian.org)|151.101.12.204|:80... …Run Code Online (Sandbox Code Playgroud)