import re


def is_valid_domain(domain):
    """Checks if a domain is syntactically valid and returns a bool"""
    if domain[-1] == ".":
        domain = domain[:-1]
    if len(domain) > 253:
        return False
    fqdn_re = re.compile("(?=^.{1,63}$)(^(?:[a-z0-9_](?:-*[a-z0-9_])+)$|^[a-z0-9]$)", re.IGNORECASE)
    return all(fqdn_re.match(d) for d in domain.split("."))