LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Learning Linux: telnet and SMTP (https://www.linuxquestions.org/questions/linux-newbie-8/learning-linux-telnet-and-smtp-4175593812/)

fanoflq 11-18-2016 02:42 PM

Learning Linux: telnet and SMTP
 
I have three questions about telnet and smtp.

First I check to see if smtp service is available on CentOS7:
Code:

[student@localhost ~]$ systemctl status | grep -i smtp
          │    └─5450 grep --color=auto -i smtp
[student@localhost ~]$

Q1: So smtp is not running, correct?
Services should show up on systemctl. No?

But on netstat, it shows smtp is running:

Code:

student@localhost ~]$ netstat -taupe | grep smtp
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 localhost:smtp          0.0.0.0:*              LISTEN      root      24224      -                 
tcp6      0      0 localhost:smtp          [::]:*                  LISTEN      root      24225      -

Looks like localhost has smtp running on all ports, 0.0.0.0:* .
Q2: So why is smtp not showing up on command output like so:
Code:

systemctl status | grep -i smtp
Since smtp is on localhost,
I should be able to telnet into localhost like so:

Code:

[student@localhost ~]$ telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 localhost.localdomain ESMTP Postfix
#Not getting a telnet prompt, "telnet>".

BUT netstat shows I am connected like so:
(Shown on last line for user, student. )
Code:

[student@localhost ~]$ netstat -taupe | grep smtp
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 localhost:smtp          0.0.0.0:*              LISTEN      root      24224      -                 
tcp6      0      0 localhost:smtp          [::]:*                  LISTEN      root      24225      -                 
tcp6      0      0 localhost:smtp          localhost:56974        ESTABLISHED postfix    59454      -                 
tcp6      0      0 localhost:56974        localhost:smtp          ESTABLISHED student    59295      5677/telnet

Q3: So why am I not getting a telnet prompt?


What did I missed?
Thanks.

Disillusionist 11-18-2016 02:47 PM

Telnet onto a different port will not provide "a telnet prompt". It performs a TCP test on the specific application running on that port

Disillusionist 11-18-2016 02:53 PM

If you telnet to port 80 on a web server, you can issue a "get" command to confirm you receive a web page.

If you telnet to port 25 on a mail server, you can issue SMTP commands like "ehlo" to confirm the SMTP service is working

Your output states you are using postfix so if you want to check the services it should be for postfix

fanoflq 11-18-2016 02:57 PM

Quote:

Originally Posted by Disillusionist (Post 5632097)
Telnet onto a different port will not provide "a telnet prompt". It performs a TCP test on the specific application running on that port


What port should I telnet?

michaelk 11-18-2016 03:00 PM

SMTP i.e Simple Mail Transfer Protocol is not a service. It is how some mail clients/servers talk to each other. The service that is running is postfix which by default runs on port 25. Since SMTP is ASCII you can use telnet to communicate with the postfix server but it isn't like a regular terminal session.

You can find many websites that post how to test SMTP via telnet.
http://www.cisco.com/c/en/us/support...te-esa-00.html
https://technet.microsoft.com/en-us/...exchg.65).aspx

Disillusionist 11-18-2016 03:00 PM

It's not that you shouldn't telnet to port 25 to test smtp access, but it will not act like a normal telnet session

It will let you issue smtp related commands and even let you send an email

fanoflq 11-18-2016 03:01 PM

Quote:

Originally Posted by Disillusionist (Post 5632104)
If you telnet to port 80 on a web server, you can issue a "get" command to confirm you receive a web page.

If you telnet to port 25 on a mail server, you can issue SMTP commands like "ehlo" to confirm the SMTP service is working

Your output states you are using postfix so if you want to check the services it should be for postfix


Code:

[student@localhost ~]$ telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 localhost.localdomain ESMTP Postfix
ehlo
501 Syntax: EHLO hostname

Thanks.
So it is working.
But why does it not show up as output of command: systemctl status ?

How do I enable a telnet prompt?

Disillusionist 11-18-2016 03:12 PM

Have you had a chance to read through the links provided by Michaelk?

From testing your service, what happens when you run:

systemctl status | grep -i postfix

fanoflq 11-18-2016 03:20 PM

Quote:

Originally Posted by Disillusionist (Post 5632117)
Have you had a chance to read through the links provided by Michaelk?

From testing your service, what happens when you run:

systemctl status | grep -i postfix

Yes...

michaelk 11-18-2016 03:25 PM

The telnet protocol works like a terminal program for human interaction to a remote computer but SMTP is not. Since it does not work the same there isn't a prompt.

fanoflq 11-18-2016 04:15 PM

One more problem.

The above OP was done using a virtual machine.
And I telnet from within the VM to its own localhost.

Its IP addresses are:

Quote:

[student@localhost ~]$ ip a | grep "inet "
inet 127.0.0.1/8 scope host lo
inet 192.168.0.17/24 brd 192.168.0.255 scope global dynamic eno16777736
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0

Not I want to telnet into the VM's smtp from its host, my laptop.
Pinging from my laptop works for both IPs:

Quote:

$ ping 192.168.0.17
PING 192.168.0.17 (192.168.0.17) 56(84) bytes of data.
64 bytes from 192.168.0.17: icmp_seq=1 ttl=64 time=0.960 ms
64 bytes from 192.168.0.17: icmp_seq=2 ttl=64 time=0.784 ms
64 bytes from 192.168.0.17: icmp_seq=3 ttl=64 time=0.836 ms
^C
--- 192.168.0.17 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.784/0.860/0.960/0.073 ms

$ ping 192.168.122.1
PING 192.168.122.1 (192.168.122.1) 56(84) bytes of data.
64 bytes from 192.168.122.1: icmp_seq=1 ttl=64 time=0.107 ms
64 bytes from 192.168.122.1: icmp_seq=2 ttl=64 time=0.093 ms
64 bytes from 192.168.122.1: icmp_seq=3 ttl=64 time=0.092 ms
^C
--- 192.168.122.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.092/0.097/0.107/0.010 ms

Then I telnet:
Quote:

$ telnet 192.168.0.17 25
Trying 192.168.0.17...
telnet: Unable to connect to remote host: Connection refused
$ telnet 192.168.122.1 25

Trying 192.168.122.1...
telnet: Unable to connect to remote host: Connection refused
$
I thought it was a firewall problem.
So I disabled the firewall:

Quote:

[student@localhost ~]$ systemctl status | grep firewall
│ ├─7667 man firewall-cmd
│ └─7947 grep --color=auto firewall
├─firewalld.service
│ └─790 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

[student@localhost ~]$ systemctl stop firewalld.service

[student@localhost ~]$ systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Fri 2016-11-18 14:44:40 MST; 11s ago
Process: 790 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
Main PID: 790 (code=exited, status=0/SUCCESS)

Nov 18 12:38:14 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Nov 18 12:38:16 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Nov 18 14:44:38 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firewall daemon...
Nov 18 14:44:40 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall daemon.
[student@localhost ~]$

And I still is not able to telnet into smtp on virtual machine:
Quote:

$ telnet 192.168.122.1 25
Trying 192.168.122.1...
telnet: Unable to connect to remote host: Connection refused

$ telnet 192.168.0.17 25
Trying 192.168.0.17...
telnet: Unable to connect to remote host: Connection refused

What did I missed?
Thanks!

michaelk 11-18-2016 04:37 PM

virbr0 is acting as a NAT router and I would guess that the host services are not listening on the virtual interface. If you want to access the host services from the guest you might need to configure it as a bridge.

Disillusionist 11-18-2016 04:40 PM

Your previous output from netstat shows smtp listening on localhost therefore it is only available from within the host

You will need to look at changing your postfix configuration to listen on the IP of the server

fanoflq 11-18-2016 05:26 PM

1 Attachment(s)
Quote:

Originally Posted by michaelk (Post 5632142)
virbr0 is acting as a NAT router and I would guess that the host services are not listening on the virtual interface. If you want to access the host services from the guest you might need to configure it as a bridge.

I have rebooted the laptop.
thus the VM's IP has changed.
Here is the VM's network setup:

Code:

[student@localhost ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:e1:93:0b brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.145/24 brd 10.0.0.255 scope global dynamic eno16777736
      valid_lft 604657sec preferred_lft 604657sec
    inet6 fe80::20c:29ff:fee1:930b/64 scope link
      valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
    link/ether 52:54:00:ae:4d:5c brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
      valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
    link/ether 52:54:00:ae:4d:5c brd ff:ff:ff:ff:ff:ff

Notice virtual bridge, virbr0, is DOWN.
And here is what I tried with no success, meaning virtual bridge's state is still DOWN:

Code:

[student@localhost ~]$ sudo ip link set virbr0 up
[student@localhost ~]$ sudo ip link show virbr0
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT
    link/ether 52:54:00:ae:4d:5c brd ff:ff:ff:ff:ff:ff


I look into nmtui, and I am not sure what to do next to enable virbr0.
virbr0 is already in nmtui.
There is no provision to turn it on in nmtui.

Here is the screen shot from VMware's setup:
(There is no add image icon button in menu area for me to insert image here!
But I was able to attach it to this pos
t.)

Looks like the setup in VMware is correct, no?

What to do?
Thanks.

michaelk 11-18-2016 05:31 PM

As Disillusionist posted postfix by default only listens to localhost. Edit inet_interfaces in the file /etc/postfix/main.cf

# Listen to all interfaces rather than strict to localhost
inet_interfaces = all

Just curious as to what you are trying to accomplish.


All times are GMT -5. The time now is 03:55 PM.