Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

Which local port is used for http or ssh protocol?

When we use web brower to use google, we type www.google.com in the web brower. I know it equals to www.google.com:80 because the default port number is 80 in http protocol.

When we use ssh to connect our local PC to remote server, we use ssh user@remote, which equals to ssh user@remote -p 22 because the default port number is 22 in ssh protocol.

My first question is: Are the default port number 80 in http or 22 in ssh local port or remote port?

I guess the answer is: remote port. Because if we use severl ssh commands to connect our local PC to several different remote servers, the default port are always 22. If we use several web browers to google something, the default port number are always 80.

My second question is: If we use severl ssh commands to connect our local PC to several different remote servers, what is the local port number for different ssh sessions? If we use severl web browers to connect our local PC to www.google.com, what is the local port number for different web browers?

question from:https://stackoverflow.com/questions/65545397/which-local-port-is-used-for-http-or-ssh-protocol

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

22 is about the remote port only.

You cannot specify a local port for an SSH connection, but as detailed here, you can use nc (or netcat) utility in order to act as a proxy:

ssh -p 33101 -o 'ProxyCommand nc -p 33101 %h %p' $SERVER_2

The -o parameter allows ssh to set the ProxyCommand option, that is: the command to use to connect to the server ( '%h' will be substituted by the host name to connect and '%p' by the port).

For HTTP connection, you could specify a local port directly using curl

The local port number is usually randomly assigned to your TCP connection by the network stack and you normally do not have to think about it much further.

Ask curl to use a local port number between 4000 and 4200 when getting this HTTPS page:

curl --local-port 4000-4200 https://example.com/

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...